Pergunta

I am wanting to give the user an option to delete their current logo and replace it with a new one. Currently I am using Stapler, a Laravel package.

I initially had trouble adding the logo, by means of, I had to create the table entity by adding the logo first, and then updating the other fields:

$company = Company::create(['logo' => Input::file('logo')]);  
$company->save();

$companyID = $company->id;
$company = Company::find($companyID);

$company->company_name = Input::get('company_name');

Now, should a user have selected a new logo to add, I want it to clear the current logo and add the new one. I am struggling on how to add the logo into the same company, as on the code above, the Company::create creates a new Company record.

Current code:

Even if I try and dd() the file directly, it returns NULL. Its as if it can't even find it within the view!

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

    if($logo !== null)
    {
        $company->logo->clear();
        $company->logo = Input::file('logo');;
    }

Thank you in advance.

Foi útil?

Solução

The form wasn't allowing file uploads. By adding:

'files'=>'true'

into the Form::open(array( it added the file.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top