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');
}
@Christonit

This comment has been minimized.

Copy link

Christonit commented Dec 6, 2018

Greetings, I've been following step by step your tutorials but somehow in this part validation isnt working: when I submit the wrong values on purposes $errors doesn't show on my view on return.

Any idea why this might be happening?

@prashant1k99

This comment has been minimized.

Copy link

prashant1k99 commented Dec 9, 2018

It's better to first test via console or try Laravel's Telescope to debug and check what's the problem.
You can find documentation about Telescope here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment