php – Uploading picture to database in laravel-ThrowExceptions

Exception or error:

I have created a form where a user can add news, and i want them to be able to upload a picture as well. I have tried too read what other users create a upload form, but cant understand it.
The picture that gets uploaded needs to store the picture path and all the other information in the database that i have created.
Reason for this is that i want to later display the news and picture that the user created, so it can be viewed.
So i need some help, since i don’t quite understand how to do this and I am a beginner in laravel. I don’t want to use any .js or other scripts since i want to learn these basics first.

My database:

class NyhetsmodulTable extends Migration {

    public function up()
        Schema::create('news', function($table)

My create.plade.php file (not sure if my file form is right):

{{ Form::open(array('route' => '', 'files' => true)) }}
        {{ Form:: label ('title', 'Title: ' )}}
        {{ Form:: text ('title')}}
        {{ Form:: label ('author', 'Author: ' )}}
        {{ Form:: text ('author')}}
        {{ Form:: label ('message', 'News: ' )}}
        {{ Form:: textarea ('message') }}
        {{ Form::file('image')}}

        {{ Form::submit('Submit') }}

My controller, that i dont understand how to set up:

public function uploadFile()


My route:

        'uses' => 'NyhetsController@uploadFile',
        'as' => 'adminpanel.newsmodule.upload'
How to solve:

Form open tag should be

{{ Form::open(array('url' => 'adminpanel.newsmodule.create', 'files' => true)) }}

in first line,
there is no need to redeclare form inside form
files should be set true, so it can send files

and to Store image,

$news = News::find(1)
$news->image = Input::file('image');

since i thougt u just save path,

$pathToFile = '/foo/bar/baz.jpg
$news->picture_path = $pathToFile;

Leave a Reply

Your email address will not be published. Required fields are marked *