求laravel5.2 controller 如何调用 models 的简单实例
比如有一个表叫abc
结构为id name time
我想写一个model(app/models/abc.php) 里面有一个方法叫 abc_db()
功能是返回abc表的id,name两列数据
然后建 一个controller(app/http/controller/test/TestController.php)
在这个文件中如何调用model并实现var_dump(abc_db()返回数据);
求以上实例,非常感谢,自己一直没整明白,主要是eloquent
回复内容:
比如有一个表叫abc
结构为id name time
我想写一个model(app/models/abc.php) 里面有一个方法叫 abc_db()
功能是返回abc表的id,name两列数据
然后建 一个controller(app/http/controller/test/TestController.php)
在这个文件中如何调用model并实现var_dump(abc_db()返回数据);
求以上实例,非常感谢,自己一直没整明白,主要是eloquent
Bank.php
<code><?php namespace App\Model; use Illuminate\Database\Eloquent\Model; class Bank extends Model { protected $fillable=['card','user_id','name','bankName','province','city','branch']; public function user(){ return $this->belongsTo(User::class); } public static function getBankById($id){ return self::findOrFail($id); } }</code>
HomeController.php
<code><?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use App\Model\Bank; class ActivityVoteController extends Controller { public function index(){ dd(Bank::getBankById(1)); } }</code></code>

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen

PHP 8.4 Installations- und Upgrade-Anleitung für Ubuntu und Debian

So richten Sie Visual Studio-Code (VS-Code) für die PHP-Entwicklung ein
