bring file and a user to the database,

0

This is the view that carries the data, the file and the name but when it reaches the controller it only sends the file

  <input type="file" name="link"  required="required">
  <textarea type="text"  rows="50" hidden="hidden" id="textosid"   name="cliente" ></textarea>
  <button type="submit" id="bot" class="btn btn-primary">Subir Boletín</button>


public function store(Request $request)
    {
        if($request->hasFile('link','cliente')){
            $cliente = $request->file('cliente');
            $link = $request->file('link');
            $file_name = time().$link->getClientOriginalName();
            $link->move(public_path().'/boletines/'.$file_name);
        }
        $file = new File();
        $file->cliente = $cliente;
        $file->name = $link->getClientOriginalName();
        $file->link = $file_name;
        $file->save();
        Session::flash('Exito','Boletin Guardado');
        return Redirect::to('file/create');
        ///view('file.create');
    }

this is the model

    protected $table = 'files'; // Nombre de la tabla que se va a llamar 
    protected $primaryKey = 'id'; // Clave primaria para identificar el usuario.
    protected $fillable = [ 'name','link','cliente'];/// los datos.
    
asked by Rojas Rodriguez Ricardo 30.10.2018 в 23:53
source

1 answer

0

If the submit sends a file and a textarea, I see several errors:

1) If the textarea has name: client, hasFile should carry only file types. In addition, the following sentence would not be logical, either:

 if($request->hasFile('link')){
      $cliente = $request->input('cliente'); 

2) If you declare the variables $ link, $ file_name, and $ client in the condition of the IF, and it is not fulfilled, when you reach the part of:

$file = new File();
$file->cliente = $cliente;
$file->name = $link->getClientOriginalName();
$file->link = $file_name;
$file->save();
Session::flash('Exito','Boletin Guardado');
return Redirect::to('file/create');
///view('file.create');

Those variables will not exist in that context.

    
answered by 31.10.2018 / 11:08
source