Search code examples
phplaravelrouteslaravel-5.3

Route Not found exception in laravel 5.3 tried resource route and manual route as well


I created a resource BrandController and then made its routes. The problem is that some routes are working and some are not. For example, create route is not working. I have also tried it to declare routes manually but problem is same. I ran command like

php artisan route:clear
php artisan cache:clear

Here are routes

Route::group(['namespace' => 'AppControllers'], function () {


/*
|--------------------------------------------------------------------------
| All routes of BrandController are defined here
|--------------------------------------------------------------------------
|
*/
Route::get('brands', 'BrandController@index')->name('brand.index');
Route::get('brand/create', 'BrandController@create')->name('brand.create');
Route::get('brand/edit/{id}', 'BrandController@edit')->name('brand.edit');
Route::delete('brand/delete/{id}', 'BrandController@destroy')->name('brand.destroy');
Route::post('brand/store', 'BrandController@store')->name('brand.store');
Route::post('brand/update/{id}', 'BrandController@update')->name('brand.update');

// Here is resource route
Route::resource('brands', 'BrandController');

});

I have created a simple a tag here it is:

<a href="{{route('brand.create')}}">Add New</a>

Whenever I click on this link it converts / into dotlike this

http://localhost:8080/rms/public/brands.create

It also generated

http://localhost:8080/rms/public/brand/create

But same issue persists. NotFoundHttpException in RouteCollection

Controller Code:

<?php

namespace App\Http\Controllers\AppControllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Brand;

class BrandController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //dd('jgh');
        //$brands = brand::all();
        return view('brands.index');
    }
/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
   return redirect('brands.create');
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(BrandRequest $request)
{
    $input          = $request->all();
    $storeBrand     = new Brand();
    $storeBrand->create($input);
    //return redirect->()->back();
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{

}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    $editBrand = Brand::findOrFail($id);
    return view('brands.edit',compact('editBrand'));
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(BrandRequest $request, $id)
{
    $updateBrand    = Brand::findOrFail($id);
    $input          = $request->all();
    $updateBrand->update($input);
    return redirect()->back();
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($id)
{
    $deleteBrand = Brand::findOrFail($id);
    $deleteBrand->delete();
    return redirect()->back();
}

}


Solution

  • Change your create method like below

    public function create()
    {
       return redirect('brands/create');
    }
    

    . notation not works in redirect method...