欢迎各位兄弟 发布技术文章
这里的技术是共享的
$user = User::create($loginuserdata); // $loginuserdata 这是键值对数组
$insertedId = $user->id; //这就可以得到 $user的id了
public function update(Request $request,$id) { $this->validate($request, [ 'title' => 'required|unique:pages,title,'.$id.'|max:255', 'body' => 'required', ]); $page = Page::find($id); $page->title = Input::get('title'); $page->body = Input::get('body'); $page->user_id = 1;//Auth::user()->id; if ($page->save()) { return Redirect::to('admin'); } else { return Redirect::back()->withInput()->withErrors('保存失败!'); } }
{ $this->validate($request, [ 'title' => 'required|unique:pages,title,'.$id.'|max:255', 'body' => 'required', ]); $page = Page::find($id); $page->title = Input::get('title'); $page->body = Input::get('body'); $page->user_id = 1;//Auth::user()->id; if ($page->save()) { return Redirect::to('admin'); } else { return Redirect::back()->withInput()->withErrors('保存失败!'); } }2)create方法
public function store() { // create里的参数是数组 if (Comment::create(Input::all())) { return Redirect::back(); } else { return Redirect::back()->withInput()->withErrors('评论发表失败!'); } } // create里的参数是数组
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Article extends Model { protected $fillable = [ 'title', 'body', 'published_at' ]; } $guarded 是排除 与 $fillable 相反 4)insert 也是数组吧
public function run()
{
$data = array(
array('people_id' => '1', 'movie_id' => '1', 'job' => '演员'),
array('people_id' => '2', 'movie_id' => '1', 'job' => '演员'),
array('people_id' => '3', 'movie_id' => '1', 'job' => '演员'),
array('people_id' => '4', 'movie_id' => '1', 'job' => '演员')
);
DB::table('movie_people')->insert($data);
}
}
$input = [
'title'=>'test 6 title',
'content'=>'test content 6',
'cat_id'=>1,
'views'=>200,
'user_id'=>1
];
$post = Post::find(6);
if($post->update($input)){
echo '更新文章成功!';
dd($post);
}else{
echo '更新文章失败!';
}
$data = array( array('orig_url'=> 'http://3g.4000512126.com/test.html', 'user_id'=>1, 'local_url'=>'http://mygn.4006363560.com/a/4000512126/test.html', 'xuanfu_tu'=>'/uploads/0dd04725d20a1a77f44bb61b8d2dfb3e.jpg', 'bottombu_tu'=>'', 'xuanfu_tel'=>'4000512126', 'xuanfu_url'=>'http://4000512126.com', 'bottombu_tu'=>'', 'bottombu_url'=>'http://4000512126.com', 'bottombu_tel'=>''),array('orig_url'=> 'http://3g.4000512126.com/test.html', 'user_id'=>1, 'local_url'=>'http://mygn.4006363560.com/a/4000512126/test.html', 'xuanfu_tu'=>'/uploads/f54f98a3230af7a41b4e8998483318e2.jpg', 'bottombu_tu'=>'', 'xuanfu_tel'=>'4000512126', 'xuanfu_url'=>'http://4000512126.com', 'bottombu_tu'=>'', 'bottombu_url'=>'http://4000512126.com', 'bottombu_tel'=>'')