PHPStorm 无法识别我在 Laravel 5.0 中的 Model 类的方法
失败将数据插入数据库,并且所有查询类和模型类的方法都未在IDE(phpStrom)中找到,我该如何解决它?
这是我的扩展类(Post.php)在这里显示最新和方法的错误:
<?php namespace App;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class Post extends Model {
protected $fillable=[
'title',
'description',
'location',
'contact',
'type',
'published_at'
];
protected $date=['published_at'];
public function setPublishedAtAttribute($date)
{
$this->attributes['published_at'] = Carbon::createFromFormat('Y-m-d', $date);
}
/**
* @param $query
*/
public function scopePublished($query)
{
$query->where('published_at', '<=', Carbon::now());
}
public function scopeUnPublished($query)
{
$query->where('published_at', '>=', Carbon::now());
}
/**
* An post is owned by a user.
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user(){
return $this->belongsTo('App\User');
}
}
这是我使用它的控制器类:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Requests\CreatePostRequest;
use App\Post;
use Request;
use Illuminate\Support\Facades\Auth;
use Session;
class PostsController extends Controller {
//
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
//return \Auth::user()->name;
$posts = Post::latest('published_at')->published()->get();
$latest= Post::latest()->first();
return view('tolet.index', compact('posts','latest'));
}
/**
* @param Post $post
* @return \Illuminate\View\View
* @internal param Articles $article
* @internal param Articles $articles
*/
public function show(Post $post)
{
return view('tolet.show', compact('post'));
}
public function create()
{
if (Auth::guest()) {
return redirect('tolet.index');
}
return view('tolet.create');
}
/**
* @param CreatePostRequest $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function store(CreatePostRequest $request)
{
//validation
$this->createPost($request);
// flash('Your tolet has been created!')->important();
return redirect('tolet.index');
}
/**
* @param Post $post
* @return \Illuminate\View\View
* @internal param Articles $article
*/
public function edit(Post $post)
{
return view('tolet.edit', compact('post'));
}
/**
* @param Post $post
* @param CreatePostRequest $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @internal param Articles $article
* @internal param $id
*/
public function update(Post $post, CreatePostRequest $request)
{
$post->update($request->all());
return redirect('tolet.index');
}
/**
* sync up the list of tags in the database
*
* @param Post $post
*/
/**
* save a new post
*
* @param CreatePostRequest $request
* @return mixed
*/
private function createPost(CreatePostRequest $request)
{
$post = Auth::user()->posts()->create($request->all());
return $post;
}
}