mercredi 18 janvier 2017

Laravel 5.2 BadMethodCallException in Controller.php line 107: Method [save] does not exist

I can't figure out why am I getting this error.

Controller: SectionHeaderController

<?php

 namespace SimpleCms\Http\Controllers;

 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Input;
 use Carbon\Carbon;
 use App\Http\Requests;
 use App\SectionHeaders;


class SectionHeaderController extends Controller
{


public function store(Request $request)
{
    $header = new SectionHeaderController();
    $this->validate($request, [
        'title' => 'required',
        'image' => 'required|mimes:jpeg,png|max:1024|dimensions:max_width=300,max_height=100',
        'heading' => 'required',
        'description' => 'required'
    ]);
    $header->title = $request->title;
    $header->heading = $request->description;
    $header->description = $request->description;
        if($request->hasFile('image')) {
        $file = Input::file('image');
        $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());

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

        $header->filePath = $name;

        $file->move(public_path().'/images/', $name);
    }
    $header->save();
    return $this->create()->with('success', 'Done!');
    }

}

Model: SectionHeaders

<?php

  namespace SimpleCms;

  use Illuminate\Database\Eloquent\Model;

  class SectionHeaders extends Model
  {

 protected $table = 'sectionheader';
 protected $fillable = [
      'title',
    'description',
    'heading',
    'image'
];

}

Routes:

Route::post('/home/store', 'SectionHeaderController@store' );

I don't know what is wrong nor how to fix this. This error appears once I hit form submit which points to this SectionHeaderController@store Any idea?

Thank you.



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

Aucun commentaire:

Enregistrer un commentaire