dimanche 22 août 2021

Laravel 8: ReflectionException Function () does not exist

I'm a beginner learning how to use Laravel 8. When I tried to execute my code, I got the error:ReflectionException Function () does not exist.

I've referred the syntax in the Laravel document #Writing Controllers, #Basic Controllers part, but the problem can't be solved.

What is the reason causing this problem and how to solve it?

The following code is my controller part in PurchaseController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;


class PurchasesController extends Controller
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function index()
    {
        return view('purchases.index');
    }

    public function purchase()
    {
        //
    }

The following part is my routing in web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PurchaseController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


Route::get('/purchases', [PurchaseController::class], 'index');
Route::post('/purchases', [PurchaseController::class], 'purchase');

Route::get('/', function () {
    return view('welcome');
});



Aucun commentaire:

Enregistrer un commentaire