Skip to content
Permalink
Browse files

Episode 18 Complete

  • Loading branch information...
JeffreyWay committed Jan 21, 2019
1 parent 2d78ee4 commit 1320ddc80709341708222e3ee330eaa96df7ba61
@@ -50,17 +50,22 @@ public function create()
*/
public function store()
{
$attributes = request()->validate([
'title' => 'required',
'description' => 'required',
'notes' => 'min:3'
]);
$project = auth()->user()->projects()->create($attributes);
$project = auth()->user()->projects()->create($this->validateRequest());
return redirect($project->path());
}
/**
* Edit the project.
*
* @param Project $project
* @return \Illuminate\Http\Response
*/
public function edit(Project $project)
{
return view('projects.edit', compact('project'));
}
/**
* Update the project.
*
@@ -72,8 +77,22 @@ public function update(Project $project)
{
$this->authorize('update', $project);
$project->update(request(['notes']));
$project->update($this->validateRequest());
return redirect($project->path());
}
/**
* Validate the request attributes.
*
* @return array
*/
protected function validateRequest()
{
return request()->validate([
'title' => 'required',
'description' => 'required',
'notes' => 'min:3'
]);
}
}
@@ -1,47 +1,19 @@
@extends ('layouts.app')

@section('content')
<form
method="POST"
action="/projects"
class="lg:w-1/2 lg:mx-auto bg-white p-6 md:py-12 md:px-16 rounded shadow"
>
@csrf

<div class="lg:w-1/2 lg:mx-auto bg-white p-6 md:py-12 md:px-16 rounded shadow">
<h1 class="text-2xl font-normal mb-10 text-center">
Lets start something new
Let's start something new
</h1>

<div class="field mb-6">
<label class="label text-sm mb-2 block" for="title">Title</label>

<div class="control">
<input
type="text"
class="input bg-transparent border border-grey-light rounded p-2 text-xs w-full"
name="title"
placeholder="My next awesome project">
</div>
</div>

<div class="field mb-6">
<label class="label text-sm mb-2 block" for="description">Description</label>

<div class="control">
<textarea
name="description"
rows="10"
class="textarea bg-transparent border border-grey-light rounded p-2 text-xs w-full"
placeholder="I should start learning piano."></textarea>
</div>
</div>

<div class="field">
<div class="control">
<button type="submit" class="button is-link mr-2">Create Project</button>

<a href="/projects">Cancel</a>
</div>
</div>
</form>
<form
method="POST"
action="/projects"
>
@include ('projects.form', [
'project' => new App\Project,
'buttonText' => 'Create Project'
])
</form>
</div>
@endsection
@@ -0,0 +1,20 @@
@extends ('layouts.app')

@section('content')
<div class="lg:w-1/2 lg:mx-auto bg-white p-6 md:py-12 md:px-16 rounded shadow">
<h1 class="text-2xl font-normal mb-10 text-center">
Edit Your Project
</h1>

<form
method="POST"
action="{{ $project->path() }}"
>
@method('PATCH')

@include ('projects.form', [
'buttonText' => 'Update Project'
])
</form>
</div>
@endsection
@@ -0,0 +1,44 @@
@csrf

<div class="field mb-6">
<label class="label text-sm mb-2 block" for="title">Title</label>

<div class="control">
<input
type="text"
class="input bg-transparent border border-grey-light rounded p-2 text-xs w-full"
name="title"
placeholder="My next awesome project"
required
value="{{ $project->title }}">
</div>
</div>

<div class="field mb-6">
<label class="label text-sm mb-2 block" for="description">Description</label>

<div class="control">
<textarea
name="description"
rows="10"
class="textarea bg-transparent border border-grey-light rounded p-2 text-xs w-full"
placeholder="I should start learning piano."
required>{{ $project->description }}</textarea>
</div>
</div>

<div class="field">
<div class="control">
<button type="submit" class="button is-link mr-2">{{ $buttonText }}</button>

<a href="{{ $project->path() }}">Cancel</a>
</div>
</div>

@if ($errors->any())
<div class="field mt-6">
@foreach ($errors->all() as $error)
<li class="text-sm text-red">{{ $error }}</li>
@endforeach
</div>
@endif
@@ -8,7 +8,7 @@
/ {{ $project->title }}
</p>

<a href="/projects/create" class="button">New Project</a>
<a href="{{ $project->path().'/edit' }}" class="button">Edit Project</a>
</div>
</header>

@@ -19,6 +19,7 @@
Route::get('/projects', 'ProjectsController@index');
Route::get('/projects/create', 'ProjectsController@create');
Route::get('/projects/{project}', 'ProjectsController@show');
Route::get('/projects/{project}/edit', 'ProjectsController@edit');
Route::patch('/projects/{project}', 'ProjectsController@update');
Route::post('/projects', 'ProjectsController@store');
@@ -19,6 +19,7 @@ public function guests_cannot_manage_projects()
$this->get('/projects')->assertRedirect('login');
$this->get('/projects/create')->assertRedirect('login');
$this->get('/projects/edit')->assertRedirect('login');
$this->get($project->path())->assertRedirect('login');
$this->post('/projects', $project->toArray())->assertRedirect('login');
}
@@ -54,9 +55,11 @@ function a_user_can_update_a_project()
$project = ProjectFactory::create();
$this->actingAs($project->owner)
->patch($project->path(), $attributes = ['notes' => 'Changed'])
->patch($project->path(), $attributes = ['title' => 'Changed', 'description' => 'Changed', 'notes' => 'Changed'])
->assertRedirect($project->path());
$this->get($project->path().'/edit')->assertOk();
$this->assertDatabaseHas('projects', $attributes);
}

0 comments on commit 1320ddc

Please sign in to comment.
You can’t perform that action at this time.