查看“入门教程”的源代码
←
入门教程
跳转至:
导航
、
搜索
因为以下原因,你没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看并复制此页面的源代码:
=入门教程= ==一个简单的例子== [http://www.golaravel.com/post/laravel-5-getting-started-part-1/ 官方教程] ===用artisan命令生成Model=== 如果是windows开发环境,把php.exe的目录添加到环境变量里,以便通过php运行artisan命令。 <source lang="bash"> php artisan make:model Article php artisan make:model Page </source> 新建的Page模型文件代码: <source lang="php"> namespace App; use Illuminate\Database\Eloquent\Model; class Page extends Model { // } </source> ===生成数据表、填充记录=== <source lang="bash"> php artisan migrate php artisan db:seed </source> ===路由=== <source lang="php"> Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () { Route::get('/', 'AdminHomeController@index'); }); </source> ===控制器=== <source lang="bash"> php artisan make:controller Admin/AdminHomeController </source> <source lang='php'> use App\Page; public function index() { return view('admin/home')->withPages(Page::all()); } </source> ===视图=== 这里有几个模板标签不能用,缺app布局模板文件,下载代码快照,那里有。 <source lang='html4strict'> @extends('app') @section('content') ... @endsection </source> ==完成Pages管理功能== ===新增“资源控制器”路由=== <source lang='php'> Route::resource('pages', 'PagesController'); </source> ===生成控制器=== <source lang='php'> php artisan make:controller Admin/PagesController </source> ===补充控制器方法=== <source lang='php'> create() store() edit() update() destory() </source> ===创建模板文件=== <source lang='php'> /resources/views/admin/pages/create.blade.php /resources/views/admin/pages/edit.blade.php </source> ====Class 'input' not found==== It is Input and not input. This commit removed Input facade definition from config/app.php hence you have to manually add that in to aliases array as below, <source lang='php'> 'Input' => Illuminate\Support\Facades\Input::class, //Or You can import Input facade directly as required, use Illuminate\Support\Facades\Input; </source> ====Undefined variable: errors in Laravel==== Add 'middleware' => 'web' for route you are using. ==前台展示页== ===权限验证=== <source lang='php'> 'middleware' => 'auth' </source> ===构建首页=== 模板里,热血名句报错。 <source lang='html4strict'> {{ Inspiring::quote() }} </source> 查看代码快照,要在config\app.php文件中引入Inspiring类。 <source lang='php'> 'Inspiring' => Illuminate\Foundation\Inspiring::class, </source> ===构建展示页=== # 路由 # 控制器 # 模板 ==加入评论功能== ===初识Eloquent=== * [http://www.golaravel.com/laravel/docs/5.0/eloquent/ Eloquent中文文档] * [https://lvwenhan.com/laravel/421.html 深入理解 Laravel Eloquent] ===创建Comment模型=== <source lang='php'> php artisan make:model Comment php artisan migrate </source> ===建立“一对多关系”=== 在page模型里加入关系声明即可。 <source lang='php'> public function hasManyComments() { return $this->hasMany('App\Comment', 'page_id', 'id'); } </source> * [http://www.golaravel.com/laravel/docs/5.0/eloquent/#relationships 关联中文文档] * [https://lvwenhan.com/laravel/423.html 深入理解 Laravel Eloquent(三)——模型间关系(关联)] ===前台提交功能=== # 路由 # 控制器 # 模板 <source lang='php'> public function store() { if (Comment::create(Input::all())) { return Redirect::back(); } else { return Redirect::back()->withInput()->withErrors('评论发表失败!'); } } </source> ;模板error变量报错,前面处理的方法在这里不适用,不知如何处理。 ===后台管理功能=== auth权限功能用不了,取消不用。 # 路由 # 控制器 # 模板 ==大作业== 用articles表,把pages表实现的功能,重新做一遍。
返回
入门教程
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息