Answer the question
In order to leave comments, you need to log in
How to correctly specify the namespace of the model so that there are no errors in laravel 5?
Hello! There was a problem in using the 5th lara, namely, I can not turn to the model.
I have a NewsController with the following content
<?php namespace App\Http\Controllers;
use Input;
use Validator;
use App\News as News;
class NewsController extends Controller {
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('news');
}
public function addnews()
{
$data = input::all();
$validator = Validator::make($data, array('title' => 'required|min:3', 'body' => 'required|min:3'));
if($validator->fails())
{
return redirect()->back()->withErrors($validator->messages(), 'addnews');
}
else
{
$addnews = \News::add();
return 'Новость успешно добавлена!';
}
}
}
$addnews = \News::add();
<?php namespace App;
class News extends Model {
public static function add($data)
{
$news = new News();
$news->title = $data['title'];
$news->body = $data['body'];
$news->save();
}
}
FatalErrorException in NewsController.php line 32:
Class 'News' 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