Laravel系列2入门使用

最好的教程是官方文档!
homestead安装好,就可以使用了。
安装Laravel
composer create-project --prefer-dist laravel/laravel blog
) <!-- Form Error List --> <div class="alert alert-danger"> <strong>Whoops! Something went wrong!</strong> <br><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif
测试错误输出:
将输入数据取不合要求的格式即可。
这个错误格式只有include它的view才能显示:@include('common.errors')
检验输入数据:如少于255个字符
如果校验失败,将重定向用户到/目录
->withErrors($validator)  will flash the errors from the given validator instance into the session so that they can be accessed via the $errors variable in our view.
Creating The Task
To create the task, we may use the save method after creating and setting properties on a new Eloquent model:
$task = new Task;
$task->name = $request->name;
$task->save();
现在的样子:
Laravel系列2入门使用
Displaying Existing Tasks
we need to edit our / route to pass all of the existing tasks to the view.
The view function accepts a second argument which is an array of data that will be made available to the view, where each key in the array will become a 变量 within the view:
Adding The Delete Button
When the button is clicked, a DELETE /task request will be sent to the application:
Note that the delete button's form method is listed as POST, even though we are responding to the request using a Route::delete route.
HTML forms only allow the GET and POST HTTP verbs, so we need a way to spoof a DELETE request from the form.
We can spoof a DELETE request by outputting the results of the method_field('DELETE') function within our form. This function generates a hidden form input that Laravel recognizes and will use to override the actual HTTP request method. The generated field will look like the following:
<input type="hidden" name="_method" value="DELETE">
We can use implicit model binding to automatically retrieve the Task model that corresponds to the {task} route parameter.
Route::delete('/task/{task}', function (Task $task) { $task->delete(); return redirect('/'); });
效果:
Laravel系列2入门使用
上一篇:Mac系统Git生成ssh公钥


下一篇:git中添加多个SSH公钥,以及不同系统之间的差别