Laravel“Method [index]不存在。”

时间:2017-10-08 08:47:20

标签: php laravel laravel-5

+--------+----------+-------------------------+-------+--------------------------------------------------------+--------------+
| Domain | Method   | URI                     | Name  | Action                                                 | Middleware   |
+--------+----------+-------------------------+-------+--------------------------------------------------------+--------------+
|        | GET|HEAD | /                       |       | App\Http\Controllers\HomeController@index              | web,auth     |
|        | POST     | /                       |       | App\Http\Controllers\HomeController@newsSubmit         | web          |
|        | POST     | announcement/get/fields |       | App\Http\Controllers\HomeController@newsGetFields      | web          |
|        | GET|HEAD | api/user                |       | Closure                                                | api,auth:api |
|        | GET|HEAD | login                   | login | App\Http\Controllers\UserController@login              | web          |
|        | POST     | login/user              |       | App\Http\Controllers\UserController@loginUser          | web          |
|        | POST     | notifications/get       |       | App\Http\Controllers\notificationsController@getNotif  | web          |
|        | POST     | notifications/read      |       | App\Http\Controllers\notificationsController@readNotif | web          |
|        | GET|HEAD | notifications/view      |       | App\Http\Controllers\notificationsController@index     | web          |
|        | GET|HEAD | register                |       | App\Http\Controllers\UserController@register           | web          |
|        | POST     | register/user           |       | App\Http\Controllers\UserController@registerUser       | web          |
+--------+----------+-------------------------+-------+--------------------------------------------------------+--------------+

这些都是我的路线:

   //notifications

Route::post('/notifications/get', 'notificationsController@getNotif');
Route::post('/notifications/read', 'notificationsController@readNotif');
Route::get('/notifications/view', 'notificationsController@index');

这是我的控制者:

<?php

namespace App\Http\Controllers;

use App\notifications;

use Illuminate\Http\Request;

class notificationsController extends Controller
{

    public function getNotif(Request $request)
    {

        $id = $request->input('id');

        $notifResult = notifications::orderBy('id', 'desc')->where('userID', '=', $id)->where('readed', '=', 0)->get();

        $data = array(
            'notifResult' => $notifResult,
            'notifNumber' => count($notifResult)
        );

        return $data;
    }

    public function readNotif(Request $request)
    {

        $notifid = $request->input('id');

        $findNotif = notifications::findOrFail($notifid);

        $findNotif->readed = 1;

        $findNotif->save();
    }

    public function index()
    {

        return view('notifications');
    }

}

只有索引1无效。

我试图在点击“查看全部”时显示所有通知,查看全部会将用户带到/ notifications / view哪个有效但是当我到达那里时,我收到"Method [index] does not exist."错误,那个是的,我假设public function index()

解决

我忘了保存文件....

1 个答案:

答案 0 :(得分:0)

试图清除您的视图和简单缓存。这可能是由于缓存。