G
G
GrimJack2016-12-31 13:31:38
Laravel
GrimJack, 2016-12-31 13:31:38

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()]);
  }
    
}

In app/Models/Faq.php:
namespace App;

use DB;
use Illuminate\Database\Eloquent\Model;

class Faq extends Model
{
  public function get_faq()
  {
    return DB::table('faq')->get();
  }
}

However, an error is thrown:
FatalThrowableError in FaqController.php line 12:
Class 'App\Models\Faq' not found

All blanks were created through artisan

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-12-31
@GrimJack

namespace App;
replace with :
namespace App\Models;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question