Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel From Scratch: Episode 15 - Two Layers of Validation
@extends('layout')
@section('content')
<h1 class="title">Create a New Project</h1>
<form method="POST" action="/projects">
@csrf
<div class="field">
<label class="label" for="title">Project Title</label>
<div class="control">
<input
type="text"
class="input {{ $errors->has('title') ? 'is-danger' : '' }}"
name="title"
value="{{ old('title') }}"
required>
</div>
</div>
<div class="field">
<label class="label" for="description">Project Description</label>
<div class="control">
<textarea
name="description"
class="textarea {{ $errors->has('description') ? 'is-danger' : '' }}"
required
>
{{ old('description') }}
</textarea>
</div>
</div>
<div class="field">
<div class="control">
<button type="submit" class="button is-link">Create Project</button>
</div>
</div>
@if ($errors->any())
<div class="notification is-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
</form>
@endsection
public function store()
{
$attributes = request()->validate([
'title' => ['required', 'min:3'],
'description' => ['required', 'min:3']
]);
Project::create($attributes);
return redirect('/projects');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment