本文整理汇总了PHP中app\models\Post::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::create方法的具体用法?PHP Post::create怎么用?PHP Post::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store()
{
$posts = \Input::get('posts');
$results = array();
if (count($posts)) {
$insertData = [];
foreach ($posts as $post) {
$tags = isset($post['tags']) ? $post['tags'] : array();
$result = Post::create(array('title' => $post['title'], 'body' => $post['body']));
if (count($tags) && $result) {
$this->savePostTags($result->id, $tags);
}
array_push($results, $result);
}
if (count($results)) {
$emails = json_decode(\Storage::get('emails.json'), true);
\Mail::send('emails.post', ['results' => $results], function ($message) use($emails) {
$message->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'));
$message->to($emails)->subject('New posts');
});
Cache::forget('all_post');
return self::makeResponse($results, 201);
} else {
return self::makeResponse(array(), 500, 'Server Error');
}
} else {
return self::makeResponse(array(), 400, 'Bad Request');
}
}
示例2: run
public function run()
{
DB::table('Posts')->delete();
Post::create(['name' => 'First Name', 'email' => 'test_mail1@test.lt', 'city' => 1, 'content' => 'First Feedbuck 24', 'slag' => 'first-feed', 'published' => true, 'created_at' => time(), 'mood' => '1']);
Post::create(['name' => 'Second Name', 'email' => 'test_mail1@test.lt', 'city' => 2, 'content' => 'Second Feedbuck 24', 'slag' => 'second-feed', 'published' => true, 'created_at' => time(), 'mood' => '2']);
Post::create(['name' => 'Third Name', 'email' => 'test_mail3@test.lt', 'city' => 3, 'content' => 'Third Feedbuck 24sdsds', 'slag' => 'third-feed', 'published' => true, 'created_at' => time(), 'mood' => '1']);
}
示例3: run
public function run()
{
DB::table('posts')->delete();
Post::create(['title' => 'First Post', 'content' => 'My first post', 'author' => 'Yevgeniy Zholkevskiy', 'published' => true]);
Post::create(['title' => 'Two Post', 'content' => 'My second post', 'author' => 'Yevgeniy Zholkevskiy', 'published' => true]);
Post::create(['title' => 'Three Post', 'content' => 'My third post', 'author' => 'Yevgeniy Zholkevskiy', 'published' => true]);
}
示例4: store
public function store(Request $request)
{
$this->validate($request, ['title' => 'required', 'content' => 'required', 'author' => 'required']);
$input = $request->all();
Post::create($input);
return redirect()->route('posts.index');
}
示例5: run
public function run()
{
DB::table('Posts')->delete();
Post::create(['title' => 'First Post', 'author' => 'Евгений', 'excerpt' => 'First Post body', 'text' => 'Content First Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
Post::create(['title' => 'Second Post', 'author' => 'Евгений', 'excerpt' => 'Second Post body', 'text' => 'Content Second Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
Post::create(['title' => 'Third Post', 'author' => 'Евгений', 'excerpt' => 'Third Post body', 'text' => 'Content Third Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
}
示例6: create
/**
* Show the application welcome screen to the user.
*
* @return Response
*/
public function create(Request $request, $id = '')
{
//echo Auth::user()->id; exit;
if (empty($id)) {
$model = new \App\Models\Post();
} else {
$model = \App\Models\Post::find($id);
if (is_null($model)) {
return response()->view('errors.404', array(), 404);
}
}
if ($request->isMethod('post')) {
$this->validate($request, ['title' => 'required|max:255', 'content' => 'required']);
$title = \Illuminate\Support\Facades\Request::input('title');
$content = \Illuminate\Support\Facades\Request::input('content');
$publish = \Illuminate\Support\Facades\Request::input('publish') === null ? 0 : 1;
if (empty($id)) {
\App\Models\Post::create(array('title' => $title, 'content' => $content, 'publish' => $publish, 'user_id' => (int) Auth::user()->id, 'created_at' => date('Y-m-d H:i:s')));
} else {
$model->fill(['title' => $title, 'content' => $content, 'publish' => $publish, 'updated_at' => date('Y-m-d H:i:s')]);
$model->save();
}
//echo "23423"; exit;
return redirect()->to('/');
}
return view('post.create')->with(compact('model'));
}
示例7: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Post $postModel, Request $request)
{
//dd($request->all());
//$request=$request->except('_token');
$postModel->create($request->all());
return redirect()->route('posts');
}
示例8: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(PostCreateRequest $request)
{
//
$post = Post::create($request->postFillData());
$post->syncTags($request->get('tags', []));
return redirect()->route('admin.post.index')->withSuccess('New Post Successful Created');
}
示例9: run
public function run()
{
DB::table('Posts')->delete();
Post::create(['title' => 'First Post', 'slug' => 'first-post', 'excerpt' => 'First Post body', 'content' => 'Content First Post body', 'published' => true, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
Post::create(['title' => 'Second Post', 'slug' => 'second-post', 'excerpt' => 'Second Post body', 'content' => 'Content Second Post body', 'published' => false, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
Post::create(['title' => 'Third Post', 'slug' => 'third-post', 'excerpt' => 'Third Post body', 'content' => 'Content Third Post body', 'published' => false, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
}
示例10: store
/**
* Store a newly created post in storage.
*
* @param CreatepostRequest $request
*
* @return Response
*/
public function store(CreatePostRequest $request)
{
$input = Request::all();
if (!empty($input['imagen'])) {
$this->carpeta = 'posts/' . $input['id_usuario'] . '/';
if (!File::exists($this->carpeta)) {
//Crear carpeta de archivos adjuntos
File::makeDirectory($this->carpeta);
}
$filename = 'posts/' . $input['id_usuario'] . '/' . $input['titulo'] . date("GisdY") . '.jpg';
$input['imagen'] = $filename;
Image::make(Input::file('imagen'))->resize(480, 360)->save($filename);
}
if (!empty($input['archivo'])) {
$this->carpeta = 'posts/' . $input['id_usuario'] . '/';
if (!File::exists($this->carpeta)) {
//Crear carpeta de archivos adjuntos
File::makeDirectory($this->carpeta);
}
$destinationPath = 'posts/' . $input['id_usuario'] . '/';
// upload path
$nombre = Input::file('archivo')->getClientOriginalName();
// getting image extension
Input::file('archivo')->move($destinationPath, $nombre);
$input['archivo'] = $destinationPath . $nombre;
}
$post = Post::create($input);
return redirect('home');
}
示例11: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
if (!$request->title or !$request->post or !$request->user_id) {
return Response::json(['error' => ['message' => 'Insufficient data']], 422);
}
$post = Post::create($request->all());
return Response::json(['message' => 'Post Created Succesfully', 'data' => $this->transform($post)]);
}
示例12: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Post::truncate();
foreach (range(1, 10) as $value) {
$faker = \Faker\Factory::create('zh_TW');
Post::create(['title' => $faker->title, 'content' => $faker->name, 'is_feature' => rand(1, 0), 'page_view' => rand(1, 1000), 'created_at' => Carbon::now()->subDays($value), 'updated_at' => Carbon::now()->subDays($value)]);
}
}
示例13: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Post::truncate();
foreach (range(10, 1) as $num) {
$faker = Faker\Factory::create('zh_TW');
Post::create(['title' => $faker->name, 'content' => $faker->sentence, 'id' => rand(0, 100), 'created_at' => $faker->dateTime($max = 'now'), 'updated_at' => Carbon::now()->subDays($num)->subYears(rand(1, 5))]);
}
}
示例14: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Post::truncate();
$faker = Factory::create('zh_tw');
foreach (range(10, 1) as $number) {
Post::create(['title' => $faker->title, 'is_feature' => rand(0, 1), 'content' => $faker->name, 'created_at' => Carbon::now()->subDay($number), 'updated_at' => Carbon::now()->subDay($number)]);
}
}
示例15: run
public function run()
{
$faker = Faker::create();
$cates = Category::lists('id')->toArray();
for ($i = 1; $i <= 50; $i++) {
Post::create(['title' => $faker->sentence(), 'summary' => $faker->paragraph(), 'category_id' => $faker->randomElement($cates), 'body' => $faker->text(10000), 'origin' => '', 'comment_count' => rand(0, 10), 'view_count' => rand(0, 200), 'favorite_count' => rand(0, 100), 'published' => rand(0, 1), 'slug' => 'post-' . $i]);
}
}