For example, there is a table called abc
The structure is id name time
I want to write a model (app/models/abc.php). There is a method called abc_db()
The function is to return the id and name data of the abc table
Then create a controller (app/http/controller/test/TestController.php)
How to call the model in this file and implement var_dump (abc_db() returns data);
Please provide the above examples, thank you very much, I have never understood it, mainly because of eloquent
For example, there is a table called abc
The structure is id name time
I want to write a model (app/models/abc.php). There is a method called abc_db()
The function is to return the id and name data of the abc table
Then create a controller (app/http/controller/test/TestController.php)
How to call the model in this file and implement var_dump (abc_db() returns data);
Please provide the above examples, thank you very much, I have never understood it, mainly because of 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>