Level 67
try
$request->validate([
'benennung' => 'required|string|max:191|min:1',
'aktiv' => 'required|boolean'
]);
Edit: Removed extra quotes. The rules should be a single string with the individual rules separated by pipes...
4 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I cant get the validate method working: My Controller:
<?php
namespace App\Http\Controllers;
use App\Artikel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Resources\artikelResource as artikelResource;
class ArtikelController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return artikelResource::collection(Artikel::all());
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
return Artikel::create($request->all());
}
/**
* Display the specified resource.
*
* @param \App\Artikel $artikel
* @return \Illuminate\Http\Response
*/
public function show(Artikel $artikel)
{
return new artikelResource($artikel);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Artikel $artikel
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Artikel $artikel)
{
$this->validate($request,[
'benennung' => 'required'|'string'|'max:191'|'min:1',
'aktiv' => 'required'|'boolean'
]);
$artikel->update($request->all());
return response()->json($artikel->fresh(), 200);
}
/**
* Remove the specified resource from storage.
*
* @param \App\Artikel $artikel
* @return \Illuminate\Http\Response
*/
public function destroy(Artikel $artikel)
{
$result = $artikel->delete();
if ($result == true){
http_response_code(204);
} else {
http_response_code(404);
}
return;
}
}
Any help is appriciated
Please or to participate in this conversation.