本文整理汇总了PHP中app\Post::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::save方法的具体用法?PHP Post::save怎么用?PHP Post::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bundlePost
function bundlePost($request)
{
$data = $request->except(['subdoot']);
$slugify = new Slugify();
$data['slug'] = $slugify->slugify($request->get('title'), '_');
if (strlen($data['slug']) > 46) {
$data['slug'] = substr($data['slug'], 0, 46);
}
//6 character string for a permalink
$permalink = $this->generateRandomString();
//Make sure the permalink is unique
while (Post::wherePermalink($permalink)->exists()) {
$permalink = $this->generateRandomString();
}
$data['permalink'] = $permalink;
//Insert the post into the db
$post = new Post($data);
//Attach the post to the user who created it
//$post->user()->associate(\App\User::find(Auth::user()->id));
// $user = \App\User::find(Auth::user()->id);
// $subdoot = Subdoot::find($request->get('subdoot'));
// $user->posts()->save($post);
// $subdoot->posts()->save($post);
$post->user()->associate(\App\User::find(Auth::user()->id));
$post->save();
$post->subdoot()->associate(Subdoot::find($request->get('subdoot')));
$post->save();
//Attach the post to the subdoot it was submitted in
//$post->subdoot()->associate(Subdoot::find($request->get('subdoot')));
return $post;
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, ['title' => 'required', 'excerpt' => 'required|max:200', 'photo_description' => 'required', 'category_id' => 'required']);
$post = new Post(array('title' => $request->get('title'), 'excerpt' => $request->get('excerpt'), 'body' => $request->get('textarea-body'), 'slug' => str_slug($request->get('title')), 'likes' => 0, 'opened' => 0, 'deleted' => 0, 'published_at' => $request->get('published_at') ? $request->get('published_at') : Carbon::now(), 'user_id' => Auth::user()->id, 'photo_description' => $request->get('photo_description'), 'category_id' => $request->get('category_id')));
$post->save();
if ($request->get('tags')) {
foreach ($request->get('tags') as $tag_id) {
$post_tags = new PostTags(array('post_id' => $post->id, 'tag_id' => $tag_id));
$post_tags->save();
}
}
if ($request->file('file')) {
$path = $this->_post_photo_path;
foreach ($request->file('file') as $file) {
$name = uniqid() . "_" . $file->getClientOriginalName();
// $coverAbsoluteFilePath = $file->getRealPath();
//$coverExtension = $file->getClientOriginalExtension();
// optimize (overwrite)
// $opt = new ImageOptimizer();
// $opt->optimizeImage($coverAbsoluteFilePath, $coverExtension);
$file->move($path, $name);
$post->photos()->create(['name' => $name, 'path' => $path]);
//unlink($path);
}
$post->save();
}
//flash()->error('Success!','Your flyer has been created');
//flash()->overlay('Success!','Your flyer has been created');
//flash()->overlay('Pavyko!','Naujiena sukurta!');
//flash()->success('Success!','Your flyer has been created');
return redirect()->back();
}
示例3: store
public function store(Request $request)
{
if ($request->thread_id) {
$this->validate($request, ['content' => 'required']);
} else {
$this->validate($request, ['title' => 'required|max:255', 'content' => 'required']);
}
// Create a new post
$post = new Post();
$post->title = $request->title;
$post->content = $request->content;
$post->forum_id = $request->forum_id;
$post->user_id = Auth::user()->id;
$post->reply_on = Carbon::now();
// Check if this is in response to another Thread
if ($request->thread_id) {
$post->thread_id = $request->thread_id;
} else {
// It's a new post, so add a slug for it
$post->slug = str_slug($request->title, '-');
}
if ($post->save()) {
// Post is made
// Update users posts count
$user = Auth::user();
$user->increment('post_count');
$user->save();
// Update the thread if required
if ($request->thread_id) {
$thread = Post::find($request->thread_id);
$thread->timestamps = false;
$thread->reply_on = Carbon::now();
$thread->save();
}
// Update the forum post count
/*
$forum = Forum::find($post->forum_id);
if($post->thread_id) {
// This is in reply to another post, update the post count
$forum->increment('reply_count');
} else {
// This is a fresh post, update topic count
$forum->increment('post_count');
}
$forum->save();
*/
Session::flash('alert-success', 'Post made!');
} else {
Session::flash('alert-error', 'Could not create post.');
}
if ($post->slug) {
// New post, send them to it
return redirect('/thread/' . $post->id . '/' . $post->slug);
} else {
// Reply to post, send them back to it
return back();
}
}
示例4: store
public function store(PostFormRequest $request)
{
$post = new Post(['title' => $request->get('title'), 'content' => $request->get('content'), 'slug' => Str::slug($request->get('title'), '-')]);
$post->save();
$post->categories()->sync($request->get('categories'));
return redirect('/admin/posts/create')->with('status', 'The post has been created!');
}
示例5: store
public function store(Request $request)
{
$post = new Post();
$post->title = $request->title;
$post->body = $request->body;
$post->save();
}
示例6: postAddContent
public function postAddContent()
{
$url = Input::get('url');
if (strpos($url, 'youtube.com/watch?v=') !== FALSE) {
$type = 'youtube';
$pieces = explode("v=", $url);
$mediaId = $pieces[1];
} else {
if (strpos($url, 'vimeo.com/channels/') !== FALSE) {
$type = 'vimeo';
$pieces = explode("/", $url);
$mediaId = $pieces[5];
} else {
if (strpos($url, 'soundcloud.com/') !== FALSE) {
$type = 'soundcloud';
$mediaId = 'null';
} else {
$type = 'other';
$mediaId = 'null';
}
}
}
$userId = Auth::id();
$post = new Post();
$post->url = $url;
$post->type = $type;
$post->userId = $userId;
$post->mediaId = $mediaId;
$post->save();
return redirect('/content')->with('success', 'Post successfully created!');
}
示例7: store
/** Save a naw post
* @param Request $request
* @return Response of the ajax request.
*/
public function store(Request $request)
{
//ajax storage.
//1. check if its out form.
if (Session::token() !== Input::get('_token')) {
return response()->json(array('message' => 'unauthorized attempt to sent a post'));
}
//get the oldest post id. this will be used to append to the post ul.
$old_post = DB::table('posts')->max('id');
//2. retreive the data in the form.
$post = new Post();
$post->title = Input::get('title');
$post->body = Input::get('body');
$post->post_author_id = Auth::id();
if ($post->save()) {
//get the profile image of the use.
$profile_image_name = Profile::find(Auth::id())->pluck('profile_image_name');
// create a json response and return it.
$response = array('title' => $post->title, 'body' => $post->body, 'post_author_id' => $post->post_author_id, 'user_id' => Auth::id(), 'profile_image_name' => $profile_image_name, 'post_id' => $post->id, 'old_post' => $old_post, 'nickname' => $request->user()->nickname, 'message' => 'Your message has been posted', 'status' => 'success');
return response()->json($response, 200);
} else {
//500 = Internal server error
return response('Sorry, An Error Occurred. Please retry the request', 500);
}
}
示例8: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Requests\CreatePostRequest $request)
{
//
//Dont forget to validate variables with the request method
$post = new Post();
$post->title = Input::get('title');
$post->artist = Input::get('artist');
$post->body = Input::get('body');
Post::create($request->all());
//get info on image if posted
if (Input::hasFile('thumbnail')) {
$file = Input::file('thumbnail');
//get name of image
$name = time() . '-' . $file->getClientOriginalName();
$file = $file->move(public_path() . '/images/', $name);
$post->thumbnail = $name;
/*
THE FOLLOWING ARE ALL THE OPTIONS YOU HAVE ACCESS TO:
return [
'path' => $file->getRealPath(),
'size' => $file->getSize(),
//'mime' => $file->getMimeType(), not working
'name' => $file->getClientOriginalName(),
'extension' =>$file->getClientOriginalExtension()
];
*/
} else {
$post->thumbnail = 'blank_avatar.jpg';
}
$post->save();
return redirect('posts');
}
示例9: store
/**
* Store a newly created resource in storage.
*
* @param CreatePostRequest $request
* @return Response
*/
public function store(CreatePostRequest $request, $category_id)
{
// save post
$post = new Post();
$post->fill($request->all());
$post->category_id = $category_id;
$post->save();
// if have attachment, create the attachment record
if ($request->hasFile('attachment')) {
// generate filename based on UUID
$filename = Uuid::generate();
$extension = $request->file('attachment')->getClientOriginalExtension();
$fullfilename = $filename . '.' . $extension;
// store the file
Image::make($request->file('attachment')->getRealPath())->resize(null, 640, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save(public_path() . '/attachments/' . $fullfilename);
// attachment record
$attachment = new Attachment();
$attachment->post_id = $post->id;
$attachment->original_filename = $request->file('attachment')->getClientOriginalName();
$attachment->filename = $fullfilename;
$attachment->mime = $request->file('attachment')->getMimeType();
$attachment->save();
}
return redirect('category/' . $category_id . '/posts');
}
示例10: store
public function store(PostsRequest $request)
{
$post = new Post();
$post->title = $request->input('title');
$post->content = $request->input('content');
$post->save();
}
示例11: store
/**
*发帖
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
if (!Auth::check()) {
return response()->json(['errno' => 2, 'msg' => 'require authentication']);
}
$title = $request->input('title');
$content = $request->input('content');
$subject_id = $request->input('subject_id');
$ba_id = $request->input('ba_id');
if (!$title || !$content || !$subject_id || !$ba_id) {
return response()->json(['errno' => 3, 'msg' => 'need title ,content ,subject_id,ba_id']);
}
$post = new Post();
$post->uid = Auth::user()->id;
$post->title = $title;
$post->content = $content;
$post->pics = $request->input('pics');
$post->subject_id = $subject_id;
$post->ba_id = $ba_id;
$post->at_users = $request->input('at_users');
$post->last_comment_id = $post->uid;
//$post->last_comment_at=time();
$post->save();
return response()->json(['errno' => 0, 'msg' => 'success', 'pid' => $post->pid]);
}
示例12: newPost
/**
* Create a new post
* @param string $body Content of post, will be run through filters
* @param integer $threadid Thread ID
* @param integer| $posterid Poster's ID. Defaults to currently authenticated user
* @param bool|false $hidden Is the post hidden from normal view?
* @param bool|true $save Should the post be automatically saved into the database?
* @return Post The resulting post object
*/
public static function newPost($body, $threadid, $posterid = null, $hidden = false, $save = true)
{
// Check users rights
if (!Auth::check() && $posterid === null) {
abort(403);
// 403 Forbidden
}
// Check thread
$thread = Thread::findOrFail($threadid);
if ($thread->locked) {
abort(403);
// 403 Forbidden
}
// Run post through filters
$body = PostProcessor::preProcess($body);
// Create new post
$post = new Post();
$post->thread_id = $threadid;
$post->poster_id = Auth::user()->id;
$post->body = $body;
$post->hidden = $hidden;
// defaults to false
// Put post into database
if ($save) {
$post->save();
}
return $post;
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$post = new Post();
$post->user_id = $request->user_id;
$post->message = $request->message;
$post->save();
}
示例14: create
public function create()
{
// dd('asdasd');
$post = new Post(['title' => 'My Awesome Blog Post', 'body' => 'My Body', 'user_id' => 1]);
$post->save();
// $post = Post::findOrFail(4);
// dd($post->slug, $post->getSlug());
}
示例15: store
public function store()
{
$post = new Post();
$post->user_id = Auth::user()->id;
$post->text = filter_var(input::get('post'), FILTER_SANITIZE_STRING);
$post->save();
return redirect('/home');
}