laravel - 在调用

时间:2016-04-19 18:14:14

标签: php laravel

我有以下路线:

       <?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', 'PagesController@index');
Route::get('item', 'ItemController@index');
Route::get('item/create', 'ItemController@create');
Route::get('item/{id}', 'ItemController@show');

Route::get('welcome', function() {
    return view('welcome');
});
Route::group(['middleware' => 'web'], function () {
    Route::auth();

    Route::get('/home', 'HomeController@index');
});

这就是我的物品控制器的样子:

@section('content');
<h1>Add a  new item</h1>
<hr />
<content>
    <div class="form-group">
    {!! Form::open() !!}
        {!! Form::label('name', "Name") !!}
        {!! Form::text('name', null, ['class' => 'form-control']) !!}
    {!! Form::close() !!}
</content>

@stopttp \请求;

use App\Item;
class ItemController extends Controller
{
public function index()
{
    //fetch all items from the database
    $items = Item::All();
    return $items;
}

public function show($id) {

    $item = Item::FindOrFail($id);
}

public function create() {
    return view::make('item.create');
}

}

create.blade.phpHere是我的视图,位于/resources/views/item/create.blade.php:@section(&#39; content&#39;);     

添加新项目

                           {! Form :: open()!!}             {! Form :: label(&#39; name&#39;,&#34; Name&#34;)!!}             {! Form :: text(&#39; name&#39;,null,[&#39; class&#39; =&gt;&#39; form-control&#39;])!!}         {! Form :: close()!!}      @stop

我正在尝试为我正在构建的基于laravel的电子商务加载项目创建方法。当我访问指定页面中的路径时,我似乎无法访问item.create视图,加载视图时只是一个空白页面;我没有看到该视图的HTML。有什么帮助吗?

这是我的日志文件的一部分:

  

[2016-04-19 17:44:41] local.ERROR:exception&#39; InvalidArgumentException&#39;消息&#39;查看[articles.create]未找到。&#39;在/home/thomas/ushop/vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php:137   堆栈跟踪:

     

0 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php(79):Illuminate \ View \ FileViewFinder-&gt; findInPaths(&#39; articles.create&#39; ,数组)

1 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/View/Factory.php(165):Illuminate \ View \ FileViewFinder-&gt; find(&#39; articles.create&#39; )

2 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(783):Illuminate \ View \ Factory-&gt; make(&#39; articles.create&#39; ,Array,Array)

3 /home/thomas/ushop/app/Http/Controllers/ItemController.php(25):view(&#39; articles.create&#39;)

4 [内部功能]:App \ Http \ Controllers \ ItemController-&gt; create()

5 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(80):call_user_func_array(Array,Array)

6 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(146):Illuminate \ Routing \ Controller-&gt; callAction(&#39; create&#39;,Array )

7 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(94):Illuminate \ Routing \ ControllerDispatcher-&gt; call(Object(App \ Http \ Controllers \ ItemController) ,对象(Illuminate \ Routing \ Route),&#39;创建&#39;)

8 [内部函数]:Illuminate \ Routing \ ControllerDispatcher-&gt; Illuminate \ Routing {closure}(Object(Illuminate \ Http \ Request))

9 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52):call_user_func(Object(Closure),Object(Illuminate \ Http \ Request))

10 [内部功能]:Illuminate \ Routing \ Pipeline-&gt; Illuminate \ Routing {closure}(Object(Illuminate \ Http \ Request))

11 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103):call_user_func(Object(Closure),Object(Illuminate \ Http \ Request))

12 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(96):Illuminate \ Pipeline \ Pipeline-&gt; then(Object(Closure))

13 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(54):Illuminate \ Routing \ ControllerDispatcher-&gt; callWithinStack(Object(App \ Http \ Controllers \ ItemController) ,对象(Illuminate \ Routing \ Route),Object(Illuminate \ Http \ Request),&#39; create&#39;)

14 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Route.php(174):Illuminate \ Routing \ ControllerDispatcher-&gt; dispatch(Object(Illuminate \ Routing \ Route),Object (照亮\ Http \ Request),&#39; App \ Http \ Contro ...&#39;,&#39;创建&#39;)

15 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Route.php(140):Illuminate \ Routing \ Route-&gt; runController(Object(Illuminate \ Http \ Request))< / H1>

16 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Router.php(724):Illuminate \ Routing \ Route-&gt; run(Object(Illuminate \ Http \ Request))< / H1>

17 [内部功能]:Illuminate \ Routing \ Router-&gt; Illuminate \ Routing {closure}(对象(Illuminate \ Http \ Request))

18 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52):call_user_func(Object(Closure),Object(Illuminate \ Http \ Request))

19 [内部函数]:Illuminate \ Routing \ Pipeline-&gt; Illuminate \ Routing {closure}(Object(Illuminate \ Http \ Request))

20 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103):call_user_func(Object(Closure),Object(Illuminate \ Http \ Request))

21 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Router.php(726):Illuminate \ Pipeline \ Pipeline-&gt; then(Object(Closure))

22 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Router.php(699):Illuminate \ Routing \ Router-&gt; runRouteWithinStack(Object(Illuminate \ Routing \ Route),Object (照亮\ HTTP \请求))

23 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Router.php(675):Illuminate \ Routing \ Router-&gt; dispatchToRoute(Object(Illuminate \ Http \ Request))< / H1>

24 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(246):Illuminate \ Routing \ Router-&gt; dispatch(Object(Illuminate \ Http \ Request)) )

25 [内部函数]:Illuminate \ Foundation \ Http \ Kernel-&gt; Illuminate \ Foundation \ Http {closure}(Object(Illuminate \ Http \ Request))

26 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52):call_user_func(Object(Closure),Object(Illuminate \ Http \ Request))

27 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44):Illuminate \ Routing \ Pipeline-&gt; Illuminate \ Routing {closure}(Object (照亮\ HTTP \请求))

28 [内部函数]:Illuminate \ Foundation \ Http \ Middleware \ CheckForMaintenanceMode-&gt; handle(Object(Illuminate \ Http \ Request),Object(Closure))

29 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124):call_user_func_array(Array,Array)

30 [内部功能]:照明\管道\管道 - &gt;照亮\管道{封闭}(对象(照明\ Http \请求))

31 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32):call_user_func(Object(Closure),Object(Illuminate \ Http \ Request))

32 [内部函数]:Illuminate \ Routing \ Pipeline-&gt; Illuminate \ Routing {closure}(Object(Illuminate \ Http \ Request))

33 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103):call_user_func(Object(Closure),Object(Illuminate \ Http \ Request))

34 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(132):Illuminate \ Pipeline \ Pipeline-&gt; then(Object(Closure))

35 /home/thomas/ushop/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99):Illuminate \ Foundation \ Http \ Kernel-&gt; sendRequestThroughRouter(Object(Illuminate \ Http \)请求))

36 /home/thomas/ushop/public/index.php(54):Illuminate \ Foundation \ Http \ Kernel-&gt; handle(Object(Illuminate \ Http \ Request))

37 {main}

3 个答案:

答案 0 :(得分:3)

  1. 您说return view::make('item.create');,应该是return View::make('item.create');return view('item.create');

  2. 日志和代码说的不同。日志谈论找不到View [articles.create],你的代码谈到了item.create View。你确定你指向正确的路线&lt; =&gt;控制器?也许尝试清除缓存

答案 1 :(得分:0)

您更改了视图,或者您有拼写错误。日志说'articles.create'没有找到,看起来你似乎没有。在你的情况下,它是item.create。

如果是拼写错误,请使用 .create而不是项 s

答案 2 :(得分:0)

由于laravel cache:clear无法删除视图缓存文件,您应该自己删除它们。转到存储->框架->视图,然后手动删除所有生成的文件