I want to use Model functions in view
My controller function code:
$model = Tickets::find(1);
View::make('view')->withModel($model);
return view('index.search', ['tickets' => $result]);
My model code:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tickets extends Model
{
public function someFunction() {
echo 'hello world!';
}
}
My view code:
{{ $model->someFunction() }}
You need to import your model like this:
use App\Tickets;
right after line with namespace so it should look something like this:
<?php
namespace App\Http\Controllers;
use App\Tickets;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With