Reputation: 597
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 dot
like this
It also generated
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();
}
}
Upvotes: 0
Views: 3121
Reputation: 150
Your can use:
public function create()
{
return redirect()->route('brands.create');
}
Or
public function create()
{
return redirect('brands/create');
}
But I am suggesting you use the first one because in that we are using route name in that. if you want to change url them you don't have to worry about this code.
Upvotes: 0
Reputation: 877
Change your create
method like below
public function create()
{
return redirect('brands/create');
}
.
notation not works in redirect
method...
Upvotes: 1
Reputation: 96
Make your resource routes like this
Route::resource('brand', 'BrandController', [
'names' => [
'index'=>'brand.list',
'create'=>'brand.create',
'store'=>'brand.store',
'update'=>'brand.update',
'edit'=>'brand.edit',
'show'=>'brand.show',
'destroy'=>'brand.remove',
]
]);
Upvotes: 0