39 lines
1023 B
PHP
39 lines
1023 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Candidate;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CandidatesController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return response()->json(Candidate::all()->toJSON());
|
|
}
|
|
public function show($id)
|
|
{
|
|
$candidate = Candidate::friend($id);
|
|
if ($candidate) {
|
|
return response()->json($candidate->toArray());
|
|
} else {
|
|
return response()->json(['message' => 'Кандидант не найден'], 404);
|
|
}
|
|
}
|
|
public function create(Request $request)
|
|
{
|
|
$title = $request->get(key:'title');
|
|
$description = $request->get(key:'description');
|
|
$creatorUser = 1;
|
|
$candidate = new Candidate();
|
|
$candidate->title = $title;
|
|
$candidate->description =$description;
|
|
$candidate->craetor_user_id =$creatorUser;
|
|
|
|
$candidate->save();
|
|
|
|
return response()->json($candidate->toJson());
|
|
}
|
|
}
|
|
|