Level 102
Show StoreCategoryRequest. Most likely the authorize() method returns false
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
This works
class CategoryController extends Controller
{
public function store(Request $request)
{
return Category::create(['name' => $request->name]);
}
}
This doesn't work
The Api client gives an error
"message": "This action is unauthorized.",
class CategoryController extends Controller
{
public function store(StoreCategoryRequest $request)
{
return Category::create(['name' => $request->name]);
}
}
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreCategoryRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
// 'name' => 'required',
];
}
}
Show StoreCategoryRequest. Most likely the authorize() method returns false
Please or to participate in this conversation.