jeudi 22 août 2019

Image is not storing in the database Laravel 5.8?

The image is not storing in the database

I already tried looking at other possible solutions but nothing work i also tried with using guessextension

public function store(Request $request)
    {

        $student = new student();

        $this->validateRequest();

        $student->name = $request->name;
        $student->address = $request->address;

    if ($request->hasFile('image')) {
        $image = $request->file('image');
        $extension = $file->getClientOriginalExtension();
        $filename=time() .'.'. $extension;
        $file->move('uploads/student/',$filename);
        $student->image = $filename;                   
    }   
    else  {
            return $request;
            $student->image ='';
    } 

     $student->save();

    return redirect()->route('show')->with('response', 'Registered Successfully');
} 

Here is the form

@extends('layouts.app')
@section('content')
<div class="container">
<form method="get" action="/student" enctype="multipart/form-data">
   

    <div class="form-group">
    <label for="email">Name:</label>
    <input type="text" class="form-control" name="name" id="email">    
  </div>

  <div class="form-group">
    <label for="pwd">Address:</label>
    <input type="text" class="form-control" name="address" id="email">
  </div>

  <div class="custom-file">
  <input type="file" name="image" class="custom-file-input" >
  <label class="custom-file-label" for="customFile">Choose file</label>
</div>

  <button type="submit" class="btn btn-primary">Submit</button>

</div>

@stop 

what i need is the image to be stored in the database



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire