🚧 Tente l'édition
This commit is contained in:
parent
5186e511a0
commit
a1876d57a2
@ -50,6 +50,25 @@ class HomeController extends Controller
|
|||||||
return view('view', ['deal' => $deal, 'type' => $type]);
|
return view('view', ['deal' => $deal, 'type' => $type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, $type, $id)
|
||||||
|
{
|
||||||
|
$folder_path = sprintf('%s/%s/%s', config('app.deals_dir'), $type, $id);
|
||||||
|
if (file_exists($folder_path)) {
|
||||||
|
$deal = new Deal(sprintf('%s/%s', config('app.deals_dir'), $type), $id);
|
||||||
|
}
|
||||||
|
if ($request->isMethod('post')) {
|
||||||
|
// TODO filter
|
||||||
|
$deal
|
||||||
|
->setSubject($request->subject)
|
||||||
|
->setBody($request->body)
|
||||||
|
->setCategory($request->category)
|
||||||
|
->setPrice($request->price);
|
||||||
|
$deal->save($folder_path);
|
||||||
|
return redirect()->route('deals.list', ['type' => $type])->with('status', ($result ? 'Deal mis à jour': 'ERREUR'));
|
||||||
|
}
|
||||||
|
return view('update', ['deal' => $deal, 'type' => $type]);
|
||||||
|
}
|
||||||
|
|
||||||
public function delete($type, $id)
|
public function delete($type, $id)
|
||||||
{
|
{
|
||||||
$result = false;
|
$result = false;
|
||||||
|
37
resources/views/update.blade.php
Normal file
37
resources/views/update.blade.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8 col-md-offset-2">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">Dashboard − <a href="<?php echo route('deals.list', ['type' => $type]); ?>">Revenir à la liste</a></div>
|
||||||
|
|
||||||
|
<div class="panel-body">
|
||||||
|
@if (session('status'))
|
||||||
|
<div class="alert alert-success">
|
||||||
|
{{ session('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<form method="post">
|
||||||
|
<label for="subject">Sujet : </label>
|
||||||
|
<input type="text" id="subject" name="subject" value="{{ $deal->getSubject() }}" />
|
||||||
|
<label for="body">Description : </label>
|
||||||
|
<textarea id="body" name="body">{{ $deal->getBody() }}</textarea>
|
||||||
|
<label for="price">Prix : </label>
|
||||||
|
<input type="text" id="price" name="price" value="{{ $deal->getPrice() }}" />
|
||||||
|
<label for="category">Catégorie : </label>
|
||||||
|
<select id="category" name="category">
|
||||||
|
<option value="">−</option>
|
||||||
|
@foreach(\Shikiryu\LBCReposter\Categories::$categories as $id => $category)
|
||||||
|
<<option value="{{ $id }}"{{ $deal->getCategory() === $id ? ' selected="selected"': '' }}>{{ $category }}</option>
|
||||||
|
</select>
|
||||||
|
<input type="submit" value="Modifier" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="panel-footer"><a href="<?php echo route('deals.list', ['type' => $type]); ?>">Revenir à la liste</a></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
@ -22,3 +22,7 @@ Route::get('/deals/list/{type}', 'HomeController@list')->name('deals.list');
|
|||||||
Route::get('/deals/view/{type}/{id}', 'HomeController@view')->name('deals.view');
|
Route::get('/deals/view/{type}/{id}', 'HomeController@view')->name('deals.view');
|
||||||
|
|
||||||
Route::get('/deals/delete/{type}/{id}', 'HomeController@delete')->name('deals.delete');
|
Route::get('/deals/delete/{type}/{id}', 'HomeController@delete')->name('deals.delete');
|
||||||
|
|
||||||
|
Route::get('/deals/update/{type}/{id}', 'HomeController@update')->name('deals.update');
|
||||||
|
|
||||||
|
Route::post('/deals/update/{type}/{id}', 'HomeController@update')->name('deals.update.post');
|
||||||
|
Loading…
Reference in New Issue
Block a user