首页 > 技术文章 > laravel5笔记

fourw 2015-08-07 16:42 原文

数据库表创建
E:\PHP\learnlaravel5>php artisan migrate

创建model
E:\PHP\learnlaravel5>php artisan make:model Article

重建数据库所有表
E:\PHP\learnlaravel5>php artisan migrate:refresh

向表中增加数据
E:\PHP\learnlaravel5>php artisan db:seed

创建controller
E:\PHP\learnlaravel5>php artisan make:controller Admin/AdminHomeController

用file_get_contents读取文件内容时,返回"null"
用文件的绝对路径即可

 

//公共AJAX请求
function ajaxRequest(u,p,c){
    $.ajax('/ajaxComment', {
        type: 'post',
        data: {'user_id':u,'page_id':p,'content':c},
        headers: {'X-CSRF-TOKEN':'{{ csrf_token() }}'},
        success: function(data, status){
            if(data==1){
                alert('评论添加成功');
            }else{
                alert('评论添加失败');
            }
    }
    });
}

//路由设置

Route::get('ajaxComment','AjaxController@store');//添加评论
Route::post('ajaxComment','AjaxController@store');//添加评论

 

// Controller方法

public function store(Request $request) {
        $CommentResult=Comment::create([
                'user_id'=>$request->input('user_id'),
                'page_id'=>$request->input('page_id'),
                'content'=>$request->input('content'),
        ]);
        if($CommentResult){
            return response('1');
        }else{
            return response('0');
        }
    }

推荐阅读