user4276926
user4276926

Reputation:

How to create a file-input and store into database using Laravel 4?

Here what I have so far, and for some reason,

I couldn't get it to save to database.

I've check everything.

Can someone tell me what did I do wrong ?

But for some reason, the file is save to my local system.

$user                = new User;
        $user->firstname = Input::get('firstname');
        $user->lastname  = Input::get('lastname');
        $user->username  = Input::get('username');
        $user->email     = Input::get('email');



$logo_path = Input::file('logo_path');

        if (Input::hasFile('logo_path'))
        {

            $file            = Input::file('logo_path');
            $destinationPath = base_path().'/app/files/logo_path/';
            $filename        = $file->getClientOriginalName();
            $uploadSuccess   = $file->move($destinationPath, $filename);
            $user->logo_path = $filename;
        }

            return Redirect::to('/users/')
            ->with('success',' Your Account has been created');

        }

Upvotes: 1

Views: 60

Answers (2)

Khan Shahrukh
Khan Shahrukh

Reputation: 6361

You did not execute save() method your code should be

$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->username = Input::get('username');
$user->email = Input::get('email');

if (Input::hasFile('logo_path'))
        {
            $allowedext = array("png","jpg","jpeg","gif");
            $photo = Input::file('logo_path');
            $destinationPath = public_path().'/uploads';
            $filename = str_random(12);
            $extension = $photo->getClientOriginalExtension();
            if(in_array($extension, $allowedext ))
            {
                $upload_success = Input::file('logo_path')->move($destinationPath, $filename.'.'.$extension);
            }
}

$user->photo = $filename ; $user->save(); please mind the variable names

Upvotes: 1

iori
iori

Reputation: 3506

I notice you forget one most important thing.

Try this $user->save(); before return Redirect. Let me know.

Upvotes: 1

Related Questions