List all paddocks, create new paddock.
All paddocks new paddocks are closed.
This commit is contained in:
95
app/Http/Controllers/PaddockController.php
Normal file
95
app/Http/Controllers/PaddockController.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Paddock;
|
||||
use Redirect;
|
||||
|
||||
class PaddockController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['paddocks'] = Paddock::orderBy('id')->paginate(10);
|
||||
|
||||
return view('paddock.list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('paddock.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
Paddock::create($request->all());
|
||||
|
||||
return Redirect::to('paddocks')
|
||||
->with('success', 'Enclos créé avec succès.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
18
app/Paddock.php
Normal file
18
app/Paddock.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Paddock extends Model
|
||||
{
|
||||
// Paddocks should be closed by default
|
||||
protected $attributes = array(
|
||||
'isClosed' => TRUE,
|
||||
);
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'isClosed',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePaddocksTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('paddocks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->boolean('isClosed');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('paddocks');
|
||||
}
|
||||
}
|
||||
17
resources/views/paddock/create.blade.php
Normal file
17
resources/views/paddock/create.blade.php
Normal file
@@ -0,0 +1,17 @@
|
||||
@extends('paddock.layout')
|
||||
|
||||
@section('content')
|
||||
<h2>Nouvel enclos</h2>
|
||||
<br>
|
||||
|
||||
<form action="{{ route('paddocks.store') }}" method="POST">
|
||||
{{ csrf_field() }}
|
||||
|
||||
<strong>Nom</strong>
|
||||
<input type="text" name="name" placeholder="Nom de l'enclos">
|
||||
<span class="text-danger">{{ $errors->first('name') }}</span>
|
||||
|
||||
<button type="submit">Créer</button>
|
||||
</form>
|
||||
|
||||
@endsection
|
||||
16
resources/views/paddock/layout.blade.php
Normal file
16
resources/views/paddock/layout.blade.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<title>Jurassic Land</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Jurassic Land</h1>
|
||||
<div class="container">
|
||||
@yield('content')
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
34
resources/views/paddock/list.blade.php
Normal file
34
resources/views/paddock/list.blade.php
Normal file
@@ -0,0 +1,34 @@
|
||||
@extends('paddock.layout')
|
||||
|
||||
@section('content')
|
||||
|
||||
@if (count($paddocks) > 0)
|
||||
<div>
|
||||
<a href="{{ route('paddocks.create') }}">Ajouter un enclos</a>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<table class="table table-bordered" id="laravel_crud">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Nom</th>
|
||||
<th>État</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($paddocks as $paddock)
|
||||
<tr>
|
||||
<td>{{ $paddock->id }}</td>
|
||||
<td>{{ $paddock->name }}</td>
|
||||
<td>{{ $paddock->isClosed ? 'Fermé' : 'Ouvert' }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
{!! $paddocks->links() !!}
|
||||
@else
|
||||
<div><p>Aucun enclos dans ce parc.</p></div>
|
||||
<div><a href="{{ route('paddocks.create') }}">Ajouter un enclos</a></div>
|
||||
@endif
|
||||
|
||||
@endsection
|
||||
@@ -14,5 +14,8 @@ use Illuminate\Support\Facades\Route;
|
||||
*/
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
return redirect('paddocks');
|
||||
});
|
||||
|
||||
|
||||
Route::resource('paddocks', 'PaddockController');
|
||||
|
||||
Reference in New Issue
Block a user