Compare commits
No commits in common. "master" and "main" have entirely different histories.
@ -27,7 +27,7 @@ class ArticleController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$article = Article::create($validated);
|
$article = Article::create($validated);
|
||||||
return redirect('/');
|
return response()->json($article, 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,6 +61,6 @@ class ArticleController extends Controller
|
|||||||
{
|
{
|
||||||
$article = Article::findOrFail($id);
|
$article = Article::findOrFail($id);
|
||||||
$article->delete();
|
$article->delete();
|
||||||
return redirect('/');
|
return response()->json(null, 204);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
|
|
||||||
class Cors
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
||||||
*/
|
|
||||||
public function handle(Request $request, Closure $next)
|
|
||||||
{
|
|
||||||
$response = $next($request);
|
|
||||||
$response->headers->set('Access-Control-Allow-Origin', '*');
|
|
||||||
$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
||||||
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +1 @@
|
|||||||
<main>
|
Api-articles
|
||||||
<form action="/api/articles" method="POST">
|
|
||||||
@csrf
|
|
||||||
<label for="titre">Titre:</label>
|
|
||||||
<input type="text" name="titre" id="titre" required><br>
|
|
||||||
|
|
||||||
<label for="contenu">Contenu:</label>
|
|
||||||
<textarea name="contenu" id="contenu" required></textarea><br>
|
|
||||||
|
|
||||||
<button type="submit">Créer un Article</button>
|
|
||||||
</form>
|
|
||||||
<h1>Articles :</h1>
|
|
||||||
@if(!empty($articles) && count($articles) > 0)
|
|
||||||
@foreach($articles as $article)
|
|
||||||
<div class="article">
|
|
||||||
<h2>{{ $article['titre'] }}</h2>
|
|
||||||
<p class="date">Publié le {{ \Carbon\Carbon::parse($article['created_at'])->format('d/m/Y à H:i') }}</p>
|
|
||||||
<p>{{ $article['contenu'] }}</p>
|
|
||||||
<form action="/api/articles/{{ $article['id'] }}" method="POST" style="display:inline;">
|
|
||||||
@csrf
|
|
||||||
@method('DELETE')
|
|
||||||
<button type="submit">Supprimer l'Article</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@endforeach
|
|
||||||
@else
|
|
||||||
<p>Aucun article disponible.</p>
|
|
||||||
@endif
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
|
@ -6,6 +6,4 @@ use Illuminate\Support\Facades\Route;
|
|||||||
use App\Http\Controllers\Api\ArticleController;
|
use App\Http\Controllers\Api\ArticleController;
|
||||||
|
|
||||||
Route::post('/articles', [ArticleController::class, 'store']);
|
Route::post('/articles', [ArticleController::class, 'store']);
|
||||||
Route::get('articles/{id}', [ArticleController::class, 'show']);
|
|
||||||
Route::put('articles/{id}', [ArticleController::class, 'update']);
|
|
||||||
Route::delete('articles/{id}', [ArticleController::class, 'destroy']);
|
|
||||||
|
@ -9,10 +9,6 @@ Route::get('/', function () {
|
|||||||
use App\Http\Controllers\Api\ArticleController;
|
use App\Http\Controllers\Api\ArticleController;
|
||||||
|
|
||||||
Route::get('articles', [ArticleController::class, 'index']);
|
Route::get('articles', [ArticleController::class, 'index']);
|
||||||
Route::get('/', function () {
|
|
||||||
$articles = (new ArticleController())->index();
|
|
||||||
return view('welcome', ['articles' => $articles]);
|
|
||||||
});
|
|
||||||
// Route::post('articles', [ArticleController::class, 'store']);
|
// Route::post('articles', [ArticleController::class, 'store']);
|
||||||
// Route::get('articles/{id}', [ArticleController::class, 'show']);
|
// Route::get('articles/{id}', [ArticleController::class, 'show']);
|
||||||
// Route::put('articles/{id}', [ArticleController::class, 'update']);
|
// Route::put('articles/{id}', [ArticleController::class, 'update']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user