Answer the question
In order to leave comments, you need to log in
How to access model from controller in laravel 5.3?
I can't find anywhere how to access the model from the controller.
Let's say a FaQ page is being created.
In routes/web.php I registered the route
In app/Http/Controllers/FaqController.php the following:Route::get('faq', '[email protected]');
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Faq;
class FaqController extends Controller
{
public function index()
{
return view('faq.index', ['urls' => Faq::get_faq()]);
}
}
namespace App;
use DB;
use Illuminate\Database\Eloquent\Model;
class Faq extends Model
{
public function get_faq()
{
return DB::table('faq')->get();
}
}
FatalThrowableError in FaqController.php line 12:
Class 'App\Models\Faq' not found
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question