jeudi 2 novembre 2017

Hidden type input value not being passed in Laravel gallery Project

I have created an album. I am trying to upload photos to the album and storing the album_id through the 'hidden' type input. When i check the source code, album_id is shown in 'value' attribute but unfortunately the value is not being passed to the query during form submission.

My create method of PhotoController which shows the form

public function create($id)
 {   
    $albums = Album::where('id',$id)->first();

    return view('admin.pages.photos',compact('albums', 'id'));
}

Here is the form.

    <div class="container">
<div class="row">
    <a class="btn btn-success" href="/gallery/">Back to Gallery</a>
    <h4>Upload Photos to <strong></strong> Gallery</h4>
    @if (session('status'))
            <div class="alert alert-success">
                
            </div>
        @endif
    <img class="thumbnail" src="/images/gallery/" alt="">     

</div>
<div class="col-md-8">
<form class="form-horizontal" action="/photo" method="POST" enctype="multipart/form-data" >
        <input type="hidden" name="_token" value="">
        <div class="form-group">
            <label class="col-md-8">Photo Title:</label>
            <input type="text" name="photo_name" class="form-control" placeholder="Name of the Photo" value="" >
        </div>
        <div class="form-group">
            <label class="col-md-8">Description</label>
            <input type="text" name="desc" class="form-control" placeholder="Write Description" value="">
        </div>
        <div class="form-group">
            <label class="col-md-8">Upload Pic</label>
            <input type="file" name="photo" class="form-control" value="" >
        </div>
        <input type="hidden" name="album_id" value="">
        <button type="submit" name="submit" class="btn btn-success waves-effect waves-light m-r-10">Submit</button>                            
    </form>

and the store method

 public function store(Request $request)
   {
        $this->validate($request, [

        'photo_name'=>'required|min:3',
        'desc'=>'required',
        'photo'=>'required'
        ]);
    $photo = new Photo;
    $photo->album_id = $request->album_id;
    $photo->photo_name = $request->photo_name;
    $str = strtolower($request->photo_name);
    $photo->slug = preg_replace('/\s+/', '-', $str);


    if($file=$request->file('photo')){

        $name = time().'.'.$file->getClientOriginalName();

        $file->move('images/gallery', $name);

        $photo['photo'] = $name;

    }
    $photo->desc = $request->desc;

    $photo->save();


    return redirect()->back()->with('status', 'Photo Successfully Added!');
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iUjlWk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire