在nginx生产服务器上找不到单个laravel路由(404)

时间:2018-02-15 16:47:55

标签: laravel

Laravel 5.4我有很多api路线,所有这些都很好。我添加了一条名为' schedules'哪个在我的开发网站上运行正常。在生产服务器上,我收到此单一路由的404错误。我使用Nginx

我的所有测试都通过了。该路线已列出。我用了php artisan route clear。我删除了一堆路线,认为可能存在路线限制。

我现在所能想到的只是名字'时间表'这导致了错误。编辑确认了名称'时间表'不是问题。

有什么想法吗?

以下是php artisan api:list

的结果
+------+-----------+---------------------------------+---------------+---------------------------------------------------------------------+-----------+------------+----------+------------+
| Host | Method    | URI                             | Name          | Action                                                              | Protected | Version(s) | Scope(s) | Rate Limit |
+------+-----------+---------------------------------+---------------+---------------------------------------------------------------------+-----------+------------+----------+------------+
|      | POST      | /api/login                      |               | App\Http\Controllers\Auth\LoginController@postLogin                 | No        | v1         |          |            |
|      | POST      | /api/register                   |               | App\Http\Controllers\Auth\RegisterController@postRegister           | No        | v1         |          |            |
|      | GET|HEAD  | /api/verify                     |               | App\Http\Controllers\Auth\AccessController@checkUserIsAuthenticated | No        | v1         |          |            |
|      | GET|HEAD  | /api/auth                       |               | App\Http\Controllers\Auth\AccessController@pageRefresh              | No        | v1         |          |            |
|      | GET|HEAD  | /api/craigsocket                |               | App\Http\Controllers\Auth\AccessController@craigSocket              | No        | v1         |          |            |
|      | GET|HEAD  | /api/dashboard                  |               | App\Http\Controllers\DashboardController@index                      | No        | v1         |          |            |
|      | GET|HEAD  | /api/dashboard/cached_page_data |               | App\Http\Controllers\DashboardController@cachedPageData             | No        | v1         |          |            |
|      | GET|HEAD  | /api/user                       |               | App\Http\Controllers\UserController@getPreferences                  | No        | v1         |          |            |
|      | POST      | /api/user                       |               | App\Http\Controllers\UserController@postPreferences                 | No        | v1         |          |            |
|      | GET|HEAD  | /api/calendar                   |               | App\Http\Controllers\CalendarController@getEvents                   | No        | v1         |          |            |
|      | PUT       | /api/calendar                   |               | App\Http\Controllers\CalendarController@update                      | No        | v1         |          |            |
|      | DELETE    | /api/calendar                   |               | App\Http\Controllers\CalendarController@destroy                     | No        | v1         |          |            |
|      | GET|HEAD  | /api/roles                      |               | App\Http\Controllers\RoleController@index                           | No        | v1         |          |            |
|      | GET|HEAD  | /api/roles/create               |               | App\Http\Controllers\RoleController@create                          | No        | v1         |          |            |
|      | GET|HEAD  | /api/roles/{id}                 |               | App\Http\Controllers\RoleController@show                            | No        | v1         |          |            |
|      | POST      | /api/roles/search               |               | App\Http\Controllers\RoleController@search                          | No        | v1         |          |            |
|      | PUT       | /api/roles                      |               | App\Http\Controllers\RoleController@update                          | No        | v1         |          |            |
|      | DELETE    | /api/roles                      |               | App\Http\Controllers\RoleController@destroy                         | No        | v1         |          |            |
|      | PUT       | /api/roles/rights               |               | App\Http\Controllers\RoleController@updateRights                    | No        | v1         |          |            |
|      | GET|HEAD  | /api/tests                      | tests.index   | App\Http\Controllers\TestController@index                           | No        | v1         |          |            |
|      | POST      | /api/tests                      | tests.store   | App\Http\Controllers\TestController@store                           | No        | v1         |          |            |
|      | GET|HEAD  | /api/tests/{test}               | tests.show    | App\Http\Controllers\TestController@show                            | No        | v1         |          |            |
|      | PUT|PATCH | /api/tests/{test}               | tests.update  | App\Http\Controllers\TestController@update                          | No        | v1         |          |            |
|      | DELETE    | /api/tests/{test}               | tests.destroy | App\Http\Controllers\TestController@destroy                         | No        | v1         |          |            |
|      | GET|HEAD  | /api/users                      |               | App\Http\Controllers\UserController@index                           | No        | v1         |          |            |
|      | GET|HEAD  | /api/users/create               |               | App\Http\Controllers\UserController@create                          | No        | v1         |          |            |
|      | GET|HEAD  | /api/users/{id}                 |               | App\Http\Controllers\UserController@show                            | No        | v1         |          |            |
|      | POST      | /api/users/search               |               | App\Http\Controllers\UserController@search                          | No        | v1         |          |            |
|      | PUT       | /api/users                      |               | App\Http\Controllers\UserController@update                          | No        | v1         |          |            |
|      | DELETE    | /api/users                      |               | App\Http\Controllers\UserController@destroy                         | No        | v1         |          |            |
|      | GET|HEAD  | /api/locations                  |               | App\Http\Controllers\LocationController@index                       | No        | v1         |          |            |
|      | GET|HEAD  | /api/locations/create           |               | App\Http\Controllers\LocationController@create                      | No        | v1         |          |            |
|      | GET|HEAD  | /api/locations/{id}             |               | App\Http\Controllers\LocationController@show                        | No        | v1         |          |            |
|      | POST      | /api/locations/search           |               | App\Http\Controllers\LocationController@search                      | No        | v1         |          |            |
|      | PUT       | /api/locations                  |               | App\Http\Controllers\LocationController@update                      | No        | v1         |          |            |
|      | DELETE    | /api/locations                  |               | App\Http\Controllers\LocationController@destroy                     | No        | v1         |          |            |
|      | GET|HEAD  | /api/terminals                  |               | App\Http\Controllers\TerminalController@index                       | No        | v1         |          |            |
|      | GET|HEAD  | /api/terminals/create           |               | App\Http\Controllers\TerminalController@create                      | No        | v1         |          |            |
|      | GET|HEAD  | /api/terminals/{id}             |               | App\Http\Controllers\TerminalController@show                        | No        | v1         |          |            |
|      | POST      | /api/terminals/search           |               | App\Http\Controllers\TerminalController@search                      | No        | v1         |          |            |
|      | PUT       | /api/terminals                  |               | App\Http\Controllers\TerminalController@update                      | No        | v1         |          |            |
|      | DELETE    | /api/terminals                  |               | App\Http\Controllers\TerminalController@destroy                     | No        | v1         |          |            |
|      | GET|HEAD  | /api/printers                   |               | App\Http\Controllers\PrinterController@index                        | No        | v1         |          |            |
|      | GET|HEAD  | /api/printers/create            |               | App\Http\Controllers\PrinterController@create                       | No        | v1         |          |            |
|      | GET|HEAD  | /api/printers/{id}              |               | App\Http\Controllers\PrinterController@show                         | No        | v1         |          |            |
|      | POST      | /api/printers/search            |               | App\Http\Controllers\PrinterController@search                       | No        | v1         |          |            |
|      | PUT       | /api/printers                   |               | App\Http\Controllers\PrinterController@update                       | No        | v1         |          |            |
|      | DELETE    | /api/printers                   |               | App\Http\Controllers\PrinterController@destroy                      | No        | v1         |          |            |
|      | GET|HEAD  | /api/vendors                    |               | App\Http\Controllers\VendorController@index                         | No        | v1         |          |            |
|      | GET|HEAD  | /api/vendors/create             |               | App\Http\Controllers\VendorController@create                        | No        | v1         |          |            |
|      | GET|HEAD  | /api/vendors/{id}               |               | App\Http\Controllers\VendorController@show                          | No        | v1         |          |            |
|      | POST      | /api/vendors/search             |               | App\Http\Controllers\VendorController@search                        | No        | v1         |          |            |
|      | PUT       | /api/vendors                    |               | App\Http\Controllers\VendorController@update                        | No        | v1         |          |            |
|      | DELETE    | /api/vendors                    |               | App\Http\Controllers\VendorController@destroy                       | No        | v1         |          |            |
|      | GET|HEAD  | /api/employees                  |               | App\Http\Controllers\EmployeeController@index                       | No        | v1         |          |            |
|      | GET|HEAD  | /api/employees/create           |               | App\Http\Controllers\EmployeeController@create                      | No        | v1         |          |            |
|      | GET|HEAD  | /api/employees/{id}             |               | App\Http\Controllers\EmployeeController@show                        | No        | v1         |          |            |
|      | POST      | /api/employees/search           |               | App\Http\Controllers\EmployeeController@search                      | No        | v1         |          |            |
|      | PUT       | /api/employees                  |               | App\Http\Controllers\EmployeeController@update                      | No        | v1         |          |            |
|      | DELETE    | /api/employees                  |               | App\Http\Controllers\EmployeeController@destroy                     | No        | v1         |          |            |
|      | GET|HEAD  | /api/accounts                   |               | App\Http\Controllers\AccountController@index                        | No        | v1         |          |            |
|      | GET|HEAD  | /api/accounts/create            |               | App\Http\Controllers\AccountController@create                       | No        | v1         |          |            |
|      | GET|HEAD  | /api/accounts/{id}              |               | App\Http\Controllers\AccountController@show                         | No        | v1         |          |            |
|      | POST      | /api/accounts/search            |               | App\Http\Controllers\AccountController@search                       | No        | v1         |          |            |
|      | PUT       | /api/accounts                   |               | App\Http\Controllers\AccountController@update                       | No        | v1         |          |            |
|      | DELETE    | /api/accounts                   |               | App\Http\Controllers\AccountController@destroy                      | No        | v1         |          |            |
|      | GET|HEAD  | /api/customers                  |               | App\Http\Controllers\CustomerController@index                       | No        | v1         |          |            |
|      | GET|HEAD  | /api/customers/create           |               | App\Http\Controllers\CustomerController@create                      | No        | v1         |          |            |
|      | GET|HEAD  | /api/customers/{id}             |               | App\Http\Controllers\CustomerController@show                        | No        | v1         |          |            |
|      | POST      | /api/customers/search           |               | App\Http\Controllers\CustomerController@search                      | No        | v1         |          |            |
|      | PUT       | /api/customers                  |               | App\Http\Controllers\CustomerController@update                      | No        | v1         |          |            |
|      | DELETE    | /api/customers                  |               | App\Http\Controllers\CustomerController@destroy                     | No        | v1         |          |            |
|      | GET|HEAD  | /api/schedules                  |               | App\Http\Controllers\ScheduleController@index                       | No        | v1         |          |            |
|      | GET|HEAD  | /api/schedules/create           |               | App\Http\Controllers\ScheduleController@create                      | No        | v1         |          |            |
|      | GET|HEAD  | /api/schedules/{id}             |               | App\Http\Controllers\ScheduleController@show                        | No        | v1         |          |            |
|      | POST      | /api/schedules/search           |               | App\Http\Controllers\ScheduleController@search                      | No        | v1         |          |            |
|      | PUT       | /api/schedules                  |               | App\Http\Controllers\ScheduleController@update                      | No        | v1         |          |            |
|      | DELETE    | /api/schedules                  |               | App\Http\Controllers\ScheduleController@destroy                     | No        | v1         |          |            |
+------+-----------+---------------------------------+---------------+---------------------------------------------------------------------+-----------+------------+----------+------------+

根据要求

api.php

<?php

use Illuminate\Http\Request;
use App\Classes\Routes\CIRoutes;


$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api)
{
    $api->group(['namespace' => 'App\Http\Controllers', 'middleware' => '\Barryvdh\Cors\HandleCors::class'], function ($api)
    {
        $api->post('login', 'Auth\LoginController@postLogin');
        $api->post('register', 'Auth\RegisterController@postRegister');

        $api->group(['middleware' => ['MyJwtMiddleWare']], function ($api)
        {
            //unrestricted authenticated user access pages

            $api->get('verify', 'Auth\AccessController@checkUserIsAuthenticated');
            $api->get('auth', 'Auth\AccessController@pageRefresh');
            $api->get('craigsocket', 'Auth\AccessController@craigSocket');
            $api->get('dashboard', 'DashboardController@index');
            $api->get('dashboard/cached_page_data', 'DashboardController@cachedPageData');
            $api->get('user/', 'UserController@getPreferences');
            $api->post('user/', 'UserController@postPreferences');

            $api->group(['middleware' => ['ViewAccess']], function ($api)
            {
                //restricted user access here....
                $api->get('calendar', 'CalendarController@getEvents');
                $api->put('calendar', 'CalendarController@update');
                $api->delete('calendar', 'CalendarController@destroy');

                CIRoutes::addRoutes($api, 'roles');
                $api->put('roles/rights', 'RoleController@updateRights');

                $api->resource('tests', 'TestController');



                CIRoutes::addRoutes($api, 'users');
                CIRoutes::addRoutes($api, 'locations');
                CIRoutes::addRoutes($api, 'terminals');
                CIRoutes::addRoutes($api, 'printers');
                CIRoutes::addRoutes($api, 'vendors');
                CIRoutes::addRoutes($api, 'employees');
                CIRoutes::addRoutes($api, 'accounts');
                CIRoutes::addRoutes($api, 'customers');
                CIRoutes::addRoutes($api, 'schedules');


            });

        });
    });
});

以下是重复路线的课程CiRoutes

class CIRoutes
{
    public static function addRoutes($api, $name, $plural = true)
    {
        if($plural){
            $n2 = ucfirst(substr($name,0,strlen($name)-1));
        }
        else{
            $n2 = ucfirst($name);
        }
       $api->get($name.'/', $n2.'Controller@index');
       $api->get($name.'/create', $n2.'Controller@create');
       $api->get($name.'/{id}', $n2.'Controller@show');
       $api->post($name.'/search', $n2.'Controller@search');
       $api->put($name.'/', $n2.'Controller@update');
       $api->delete($name.'/', $n2.'Controller@destroy');
    }
}

*********** ScheduleController.php **********************

<?php

namespace App\Http\Controllers;

use App\Models\Tenant\CalendarEntry;
use App\Models\Tenant\Employee;
use Illuminate\Http\Request;

use App\Http\Requests;

use Carbon\Carbon;

class ScheduleController extends Controller
{
    public function returnData()
    {
        $return_data = [];
        $return_data['employees'] = Employee::employeeSelectArray();

        return $return_data;
    }

    public function index(Request $request)
    {
        $entries = CalendarEntry::where('class_name', 'scheduled_shift')->get();
        $number_of_records_available = $entries->count();
        $return_data = $this->returnData();
        $return_data['records'] = []; //let js handle the data through ajax
        $return_data['number_of_records_available'] = $number_of_records_available;
        if ($number_of_records_available <= $request->number_of_records)
        {
            $return_data['records'] = $entries;
        }

        return response()->json([
            'success' => true,
            'message' => 'search returned',
            'data' => $return_data
        ], 200);


    }

    public function search(Request $request)
    {
        $data = $request->all();
        $table_name = $data['table_name'] . '_';
        $search = $data['search_fields'];
        $title = $search[ $table_name . 'title' ];
        $comments = $search[ $table_name . 'comments' ];
        $from = $search[ $table_name . 'start' ];
        $to = $search[ $table_name . 'end' ];
        $employee_id = $search[ $table_name . 'employee_id' ];


        $q = CalendarEntry::where('title', 'LIKE', "%{$title}%")
            ->where('comments', 'LIKE', "%{$comments}%")
            ->where('class_name', 'scheduled_shift');
        if ($employee_id != "null")
        {
            $q->where('employee_id', $employee_id);
        }
        if ($from != '')
        {
            $from = $from . ' 00:00:00';
            $from = Carbon::createFromFormat('Y-m-d H:i:s', $from);

            if ($to != '')
            {
                $to = $to . ' 00:00:00';
                $to = Carbon::createFromFormat('Y-m-d H:i:s', $to);
                //add one day to include the end date results
                $to->addDays(1);

                $q->where('end', '>=', $from)
                    ->where('end', '<=', $to);
            } else
            {
                $q->where('end', '>=', $from);
            }

        }

        $return_data = $this->returnData();
        $records = $q->get();
        //need to calculate total hours and pay per entry
        foreach($records as &$record){
            $record['hours'] = $record->hours($from,$to);
            $record['rate'] = $record->employee()->pay_rate;
            $record['pay'] = $record->employee()->pay_rate*$record['hours'];
        }
        $return_data['records'] =  $records;


        return response()->json([
            'success' => true,
            'message' => 'search returned',
            'data' => $return_data
        ], 200);


    }

    public function create()
    {
        //send back data needed to create
        $return_data = $this->returnData();

        $return_data['records'] = [];

        return response()->json([
            'success' => true,
            'message' => 'search returned',
            'data' => $return_data
        ], 200);
    }

    public function show($id)
    {
        $data = CalendarEntry::findOrFail($id);
        $return_data = $this->returnData();
        $start = Carbon::createFromFormat('Y-m-d H:i:s', $data->start);
        $end = Carbon::createFromFormat('Y-m-d H:i:s', $data->end);
        $return_data['start_date'] = $start->toDateString();
        $return_data['start_time'] = $start->toTimeString();
        $return_data['end_date'] = $end->toDateString();
        $return_data['end_time'] = $end->toTimeString();


        $return_data['page'] = 'show';
        $return_data['records'] = [$data]; //let js handle the data through ajax
        return response()->json([
            'success' => true,
            'message' => 'search returned',
            'data' => $return_data
        ], 200);


    }

    public function update(Request $request)
    {
        $data = $request->data[0];

        $id = $data['id'];
        //$end = scrubDate($data['end_date'], $data['end_time']);
        //$start = scrubDate($data['start_date'], $data['start_time']);

        $fill = [];
        $fill['id'] = $id;
        $fill['class_name'] = 'scheduled_shift';
        $fill['employee_id'] = $data['employee_id'];
        $fill['title'] = $data['title'];
        $fill['start'] = $data['start'];
        $fill['end'] = $data['end'];


        $rules = array(
            'title' => 'required',
            'employee_id'=>'required',
            'start' => 'required|date',
            'end' => 'required|date|after:' . $data['start'],
        );

        $validation = \Validator::make($fill, $rules);
        if ($validation->passes())
        {



            $update = CalendarEntry::firstOrNew(['id' => $id]);

            $update->fill($fill);
            if ($update->save())
            {
                return response()->json([
                    'success' => true,
                    'message' => 'record updated',
                    'id' => $update['id']
                ], 200);
            }
        }
        $errors = $validation->errors();
        $errors = json_decode($errors);

        return response()->json([
            'success' => false,
            'message' => $errors
        ], 422);
    }

    public function destroy(Request $request)
    {
        //just call the calendar to delete
        $cc = new CalendarController();

        return $cc->destroy($request);

    }

}

0 个答案:

没有答案