Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'App\Http\Controllers\Model' not found

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() }}
like image 367
Ostap Brehin Avatar asked Dec 11 '25 14:12

Ostap Brehin


1 Answers

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;
like image 166
Marcin Nabiałek Avatar answered Dec 14 '25 04:12

Marcin Nabiałek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!