make a function on a Laravel Controller that receive a user id find on database and…
- User
make a function on a Laravel Controller that receive a user id find on database and return as a json.
Assistant
Sure! Here's an example of how you could create a function on a Laravel controller that receives a user ID and returns the user's data as JSON:
use App\Models\User; use Illuminate\Http\Request; class UserController extends Controller { public function getUser($id) { $user = User::find($id); if (!$user) { return response()->json(['error' => 'User not found'], 404); } return response()->json($user); } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.