I have a form that uploads an image file to a post, very simply and it uses image intervention
"intervention/image": "dev-master"
so I can resize it etc but at the moment its a simple post action like so:
<?php namespace Boroughcc\Http\Controllers;
use Input;
use Redirect;
use Storage;
use SirTrevorJs;
use STConverter;
use Validator;
use Image;
use Boroughcc\Post;
use Boroughcc\Http\Requests;
use Boroughcc\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PostsController extends Controller {
public function store()
{
// image upload function
// $img = Image::make(Input::file('featured_image'));
// dd($img);
$input = Input::all();
$validation = Validator::make($input, Post::$rules);
$entry = array(
'title' => Input::get('title'),
'featured_image' => Input::file('featured_image')
);
if ($validation->passes())
{
$img = Image::make(Input::file('featured_image'));
$pathinfo = pathinfo($img);
$type = $pathinfo['basename'];
$filename = date('Y-m-d-H:i:s').$type;
$path = 'img/posts/' . $filename;
$img->save($path);
$post = Post::create(
$entry
);
return Redirect::route('posts.index')->with('message', 'Post created');
} else {
return Redirect::route('posts.create')
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors.');
}
//Post::create( $input );
// return Redirect::route('posts.index')->with('message', 'Post created');
}
The post checks for validations and if all are correct it sends the post to save it and should hopefully generate the file. When it saves it the file goes into my /public/img/posts/
folder fine. here is the post model below;
Post.php
<?php namespace Boroughcc;
use Illuminate\Database\Eloquent\Model;
class Post extends Model {
//
protected $guarded = [];
public static $rules = array(
'title' => 'required',
'featured_image' => 'required|image|mimes:jpeg,jpg,png,bmp,gif,svg'
);
}
So you can see what I am trying to output here is what I am using in the post.index page to output the image url here:
{!! Form::model(new Boroughcc\Post, ['route' => ['posts.store'], 'files' => true]) !!}
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title') !!}
</div>
<div class="form-group">
<strong>Only edit this if necessary, this is auto populated</strong><br>
{!! Form::label('slug', 'Slug:') !!}
{!! Form::text('slug') !!}
</div>
<div class="form-group">
{!! Form::label('featured_image', 'Featured Image:') !!}
{!! Form::file('featured_image') !!}
</div>
<div class="form-group">
{!! Form::label('body', 'Post body:') !!}
{!! Form::textarea('body', null, array('id'=>'','class'=>'sir-trevor')) !!}
</div>
<div class="form-group">
{!! Form::submit($submit_text, ['class'=>'btn primary']) !!}
</div>
{!! Form::close() !!}
When I go to get the file url to output I get this instead:
"featured_image" => "/private/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/phpMEtuuA"
This is what I get, is there something wrong with this and why is it rendering this only?