Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对象注入错误_Php_Laravel_Laravel 5_Laravel 5.4 - Fatal编程技术网

Php 对象注入错误

Php 对象注入错误,php,laravel,laravel-5,laravel-5.4,Php,Laravel,Laravel 5,Laravel 5.4,我正在从事一个Laravel 5.4项目。我面临一个问题。我想更多地了解这个问题 下面的代码正在工作 PostController.php <?php namespace App\Http\Controllers; use DB; use View; use App\Model\Book; use App\Model\Chapter; use App\Model\Post; class PostController extends Controller { public

我正在从事一个Laravel 5.4项目。我面临一个问题。我想更多地了解这个问题

下面的代码正在工作

PostController.php

<?php

namespace App\Http\Controllers;

use DB;
use View;
use App\Model\Book;
use App\Model\Chapter;
use App\Model\Post;

class PostController extends Controller
{
      public function index(Book $book,Chapter $chapter)
      {
            $books = Book::all();
            $posts = Post::get_post($book,$chapter);

            $data = array(
                'posts'     => $posts,
                'books'       => $books,
                'section_id'  => ''
            );

            return View::make('posts')->with($data);
      }
}  
<?php

namespace App\Http\Controllers;

use DB;
use View;
use App\Model\Book;
use App\Model\Chapter;
use App\Model\Post;

class PostController extends Controller
{
      public function index(Book $book,Chapter $chapter)
      {
            $books = Book::all();
            $posts = Post::get_post(Book $book,Chapter $chapter); //issue is in this line

            $data = array(
                'posts'     => $posts,
                'books'       => $books,
                'section_id'  => ''
            );

            return View::make('posts')->with($data);
      }
}

此行的问题:

$posts = Post::get_post(Book $book,Chapter $chapter); //issue is in this line
调用函数时,不会键入提示类型。您应该像这样运行函数:

$posts = Post::get_post($book, $chapter);
public static function get_post(Book $book,Chapter $chapter) 
{
  // do whatever you want here
}
是的,您可以这样声明get_post函数:

$posts = Post::get_post($book, $chapter);
public static function get_post(Book $book,Chapter $chapter) 
{
  // do whatever you want here
}

但是现在,当你打电话时,你不再使用
Book
Chapter
这一行的问题:

$posts = Post::get_post(Book $book,Chapter $chapter); //issue is in this line
调用函数时,不会键入提示类型。您应该像这样运行函数:

$posts = Post::get_post($book, $chapter);
public static function get_post(Book $book,Chapter $chapter) 
{
  // do whatever you want here
}
是的,您可以这样声明get_post函数:

$posts = Post::get_post($book, $chapter);
public static function get_post(Book $book,Chapter $chapter) 
{
  // do whatever you want here
}

但是现在当你打电话时,你不再在这个函数中使用
Book
Chapter

公共函数索引(Book$Book,Chapter$Chapter)()了,你从那里得到$Book我从模型中得到了这个
$Book
。谢谢如果您调用的模型正确,那么无需再次通过..公共函数索引(Book$Book,Chapter$Chapter)()在这个函数中,您从那里获取$Book我从模型获得这个
$Book
。谢谢,如果你打对了模特,那么就不用再打了。。