NotFoundHttpException в Application.php в люмене - PullRequest
0 голосов
/ 15 июня 2019

Я новичок в Laravel и lumen и пытаюсь создать API для создания, удаления, обновления и просмотра однопользовательской информации пользователя. Есть UserController и его функции. Маршруты определены в файле rout.php. Но когда я отправляю любой запрос, он показывает «Извините, страница, которую вы ищете, не может быть найдена». Пожалуйста, помогите.

Я попытался Решение по переполнению стека для той же проблемы , но оно мне не помогло.

Мой код контроллера, как показано ниже

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
class UserController extends Controller
{
    
    protected $fillable = [
        'name', 'email', 'phone', 'password', 'password_confirmation', 'address'
    ];    
    public function showAllUsers()
    {
        return response()->json(User::all());
    }

    public function showOneUser($id)
    {
        echo "string";
        return response()->json(User::find($id));
    }

    public function create(Request $request)
    {
        $user = User::create($request->all());

        return response()->json($user, 201);
    }

    public function update($id, Request $request)
    {
        $user = User::findOrFail($id);
        $user->update($request->all());

        return response()->json($user, 200);
    }

    public function delete($id)
    {
        User::findOrFail($id)->delete();
        return response('Deleted Successfully', 200);
    }

}

Маршруты определены следующим образом

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$app->get('/', function () use ($app) {
    return $app->welcome();
});
  $app->get('user',  ['uses' => 'UserController@showAllUserControllers']);

  $app->get('user/{id}', ['uses' => 'UserController@showOneUserController']);

  $app->post('user', ['uses' => 'UserController@create']);

  $app->delete('user/{id}', ['uses' => 'UserController@delete']);

  $app->put('user/{id}', ['uses' => 'UserController@update']);

В соответствии с предложенным ответом я сделал следующие изменения в public / index.php

<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/

$app = require __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

// $app->run();
// $app->run($app->request);
$app->run(
    $app->make('request')
);
...