<bdo id='YypPI'></bdo><ul id='YypPI'></ul>

  • <i id='YypPI'><tr id='YypPI'><dt id='YypPI'><q id='YypPI'><span id='YypPI'><b id='YypPI'><form id='YypPI'><ins id='YypPI'></ins><ul id='YypPI'></ul><sub id='YypPI'></sub></form><legend id='YypPI'></legend><bdo id='YypPI'><pre id='YypPI'><center id='YypPI'></center></pre></bdo></b><th id='YypPI'></th></span></q></dt></tr></i><div id='YypPI'><tfoot id='YypPI'></tfoot><dl id='YypPI'><fieldset id='YypPI'></fieldset></dl></div>

        <tfoot id='YypPI'></tfoot>
      1. <legend id='YypPI'><style id='YypPI'><dir id='YypPI'><q id='YypPI'></q></dir></style></legend>

        <small id='YypPI'></small><noframes id='YypPI'>

      2. PHPStorm 无法识别 Laravel 5.0 中我的模型类的方法

        时间:2023-09-24
          <bdo id='2sKqe'></bdo><ul id='2sKqe'></ul>

              <tfoot id='2sKqe'></tfoot>

              <i id='2sKqe'><tr id='2sKqe'><dt id='2sKqe'><q id='2sKqe'><span id='2sKqe'><b id='2sKqe'><form id='2sKqe'><ins id='2sKqe'></ins><ul id='2sKqe'></ul><sub id='2sKqe'></sub></form><legend id='2sKqe'></legend><bdo id='2sKqe'><pre id='2sKqe'><center id='2sKqe'></center></pre></bdo></b><th id='2sKqe'></th></span></q></dt></tr></i><div id='2sKqe'><tfoot id='2sKqe'></tfoot><dl id='2sKqe'><fieldset id='2sKqe'></fieldset></dl></div>
                <tbody id='2sKqe'></tbody>

              <small id='2sKqe'></small><noframes id='2sKqe'>

              <legend id='2sKqe'><style id='2sKqe'><dir id='2sKqe'><q id='2sKqe'></q></dir></style></legend>
                  本文介绍了PHPStorm 无法识别 Laravel 5.0 中我的模型类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  向数据库中插入数据失败,IDE (phpStrom) 中未找到所有查询类和模型类的方法,我该如何解决?

                  failed insert data into database, and all query class and Model class's method not found show in IDE (phpStrom) how can I solve it?

                  这是我的扩展类(Post.php),这里显示最新的错误和方法:

                  here is my extended class (Post.php) here show error in latest and where method:

                  <?php namespace App;
                  
                  use CarbonCarbon;
                  use IlluminateDatabaseEloquentModel;
                  
                  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 IlluminateDatabaseEloquentRelationsBelongsTo
                       */
                      public function user(){
                          return $this->belongsTo('AppUser');
                      }
                  
                  } 
                  

                  这是我使用它的控制器类:

                  and Here is my Controller class where i use it :

                  <?php namespace AppHttpControllers;
                  
                  use AppHttpRequests;
                  
                  use AppHttpRequestsCreatePostRequest;
                  use AppPost;
                  use Request;
                  use IlluminateSupportFacadesAuth;
                  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 IlluminateViewView
                       * @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 IlluminateHttpRedirectResponse|IlluminateRoutingRedirector
                       */
                      public function store(CreatePostRequest $request)
                      {
                          //validation
                  
                          $this->createPost($request);
                  
                  
                         // flash('Your tolet has been created!')->important();
                  
                          return redirect('tolet.index');
                      }
                  
                      /**
                       * @param Post $post
                       * @return IlluminateViewView
                       * @internal param Articles $article
                       */
                      public function edit(Post $post)
                      {
                          return view('tolet.edit', compact('post'));
                      }
                  
                  
                      /**
                       * @param Post $post
                       * @param CreatePostRequest $request
                       * @return IlluminateHttpRedirectResponse|IlluminateRoutingRedirector
                       * @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;
                      }
                  
                  
                  }
                  

                  推荐答案

                  如果你想要一个扩展 Model 的类来识别 Eloquent 方法,只需在该类的 PHPDoc 顶部注释中添加以下内容:

                  If you want a class extending Model to recognize Eloquent methods, just add the following in the top PHPDoc comment on the class:

                  @mixin Eloquent
                  

                  示例:

                  <?php namespace App;
                  
                  use CarbonCarbon;
                  use Eloquent;
                  use IlluminateDatabaseEloquentModel;
                  
                  /**
                   * Post
                   *
                   * @mixin Eloquent
                   */
                  class Post extends Model {
                  

                  编辑 Laravel 6+

                  use IlluminateDatabaseEloquentBuilder;
                  
                  /**
                   * @mixin Builder
                   */
                  

                  注意:你们中的大多数人可能正在为 Laravel 使用 ide-helper,因此这个 @mixin 属性为模型类自动生成.

                  Note: Most of you probably are using ide-helper for Laravel, therefore this @mixin attribute is automatically generated for model Classes.

                  这篇关于PHPStorm 无法识别 Laravel 5.0 中我的模型类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel hasMany 和belongsTo 参数 下一篇:Laravel hasMany 关系统计帖子的点赞数和评论数

                  相关文章

                  最新文章

                1. <tfoot id='4LDzj'></tfoot>

                    • <bdo id='4LDzj'></bdo><ul id='4LDzj'></ul>

                      <legend id='4LDzj'><style id='4LDzj'><dir id='4LDzj'><q id='4LDzj'></q></dir></style></legend>
                      <i id='4LDzj'><tr id='4LDzj'><dt id='4LDzj'><q id='4LDzj'><span id='4LDzj'><b id='4LDzj'><form id='4LDzj'><ins id='4LDzj'></ins><ul id='4LDzj'></ul><sub id='4LDzj'></sub></form><legend id='4LDzj'></legend><bdo id='4LDzj'><pre id='4LDzj'><center id='4LDzj'></center></pre></bdo></b><th id='4LDzj'></th></span></q></dt></tr></i><div id='4LDzj'><tfoot id='4LDzj'></tfoot><dl id='4LDzj'><fieldset id='4LDzj'></fieldset></dl></div>

                      <small id='4LDzj'></small><noframes id='4LDzj'>