Level 73
You are missing the import in your controller, so at the top add:
use App\Http\Requests\CategoryStoreRequest;
So i have a form which is supposed to upload data to the database so i created a request and a controller to perfom this but im simply getting the error Class
"App\Http\Controllers\Admin\CategoryStoreRequest" does not exist
I already called requst in the controller but its not working
use Illuminate\Http\Request;
My Controller
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Category;
class CategoryController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$categories =Category::all();
return view('admin.categories.index', compact('categories'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.categories.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(CategoryStoreRequest $request)
{
$image = $request->file('image')->store('public/categories');
Category::create([
'name' => $request->name,
'description' => $request->description,
'image' => $image
]);
return to_route('admin.categories.index');
}
/**
* 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)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
My CategoryStoreRequest
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\Category;
class CategoryStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'name' =>['required'],
'image' =>['required','image'],
'description' =>['required'],
];
}
}
You are missing the import in your controller, so at the top add:
use App\Http\Requests\CategoryStoreRequest;
Please or to participate in this conversation.