my first commit
This commit is contained in:
38
app/Http/Controllers/CandidatesController.php
Normal file
38
app/Http/Controllers/CandidatesController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
|
||||
10
app/Http/Controllers/CandidatsController.php
Normal file
10
app/Http/Controllers/CandidatsController.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CandidatsController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
8
app/Http/Controllers/Controller.php
Normal file
8
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
Reference in New Issue
Block a user