Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // create the validator
     $validator = Validator::make(Input::all(), Post::$rules);
     // attempt validation
     if ($validator->fails()) {
         Session::flash('errorMessage', 'Something went wrong.');
         return Redirect::back()->withInput()->withErrors($validator);
     } else {
         $post = new Post();
         $title = Input::get('title');
         $body = Input::get('body');
         if (Request::hasFile('file')) {
             $img = Imageupload::upload(Request::file('file'));
             $post->img_url = $img['filename'];
         }
         $post->title = $title;
         $post->body = $body;
         $post->user_id = Auth::id();
         $post->save();
         $post_id = $post->id;
         $tags = Input::get('tags');
         if (isset($tags)) {
             $tags = strtolower(Input::get('tags'));
             $tags = explode(', ', $tags);
             foreach ($tags as $tag) {
                 $tag = trim($tag);
                 $tag_id = Tag::firstOrCreate(array('name' => $tag));
                 $post->tags()->attach($tag_id, array('post_id' => $post_id));
             }
         }
         Log::info('Success: ', ['title' => $post->title, 'body' => $post->body]);
         Session::flash('successMessage', 'You created a post successfully');
         return Redirect::action('PostsController@index');
     }
 }
<?php

Route::any('matriphe/imageupload', function () {
    $data = [];
    echo config('imageupload.library');
    if (Request::hasFile('file')) {
        $data['result'] = Imageupload::upload(Request::file('file'));
    }
    return view('imageupload::form')->with($data);
});