dimanche 30 octobre 2016

Working the check box laravel 5.2

I am having problem working my check box basically am trying to save in a diff location if checkbox is true don't know what am doing wrong here is my code.Error displays

FatalErrorException in PostController.php line 64:syntax error, unexpected 'if' (T_IF)

thanks in advance.

creat.blade`

            <div>
                
                

            </div>

Postcontroller`

<?php 
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Post;
use Session;

use Image;
class PostController extends Controller
{
    public function __construct() {
        $this->middleware('auth');
    }

    public function store(Request $request)
    {
        // validate the data
        $this->validate($request, array(
                'title'         => 'required|max:255',
                'body'          => 'required'
            ));
        // store in the database
        $post = new Post;
        $post->title = $request->title;
        $post->body = $request->body;
        $checkbox = Input::get('check_box');

        $post->$checkbox

        if ($request->hasFile('featured_image')) {

          $image = $request->file('featured_image');
          $filename = time() . '.' . $image->getClientOriginalExtension();

            if (Input::get('check_box') === 'true') {
                $post->checkbox = 'true';  // UPDATE:must be true of course
                $location = public_path('images/profile' . $filename);
              Image::make($image->getRealPath())->resize('800', '400')->save($location);

            $post->image = $filename;

            } else {
                $post->checkbox = 'false'; // UPDATE:must be false of course
                $location = public_path('images/' . $filename);
              Image::make($image->getRealPath())->resize('800', '400')->save($location);


          $post->image = $filename;

        }

        $post->save();

        Session::flash('success', 'The blog post was successfully save!');
        return redirect()->route('posts.show', $post->id);
    }
    public function show($id)
    {
        $post = Post::find($id);
        return view('posts.show')->withPost($post);}
?>

Aucun commentaire:

Enregistrer un commentaire