Jeff P.
Jeff P.

Reputation: 3004

Laravel PHP: Creating default object from empty value error

I'm using a controller to call up a form defined in one of my views. Within the controller, I have a simple 'create()' method that I just want to use to call up a form while using the 'Video' model I've defined. The problem is when I try to call this function, I keep getting a 'Creating default object from empty value' error.

Controller(app\VideosController.php):

 <?php 

use Acme\repositories\VideoRepository;

use Models\Video;

use Models\Validators as Validators;

class VideosController extends BaseController {

/**
 * The video model
 *
 * @var \Models\Video
 **/
protected $video;


/*  The value defined from my repository
*/

protected $videoRepo;

/**
 * Instantiate the controller
 *
 * @param Models\Video $video
 * @return void
 **/

   public function __construct(VideoRepository $videoRepo)
   {
     $this->videoRepo = $videoRepo;
     /* Old code below 
     $this->video = \App::make('Repositories\VideoRepository');
     */
   }

/* Create a new video by passing in a sub view
Of the form for creating a new video */

   public function create()
   {
    $data = array('type' => 'video');
    $this->layout->content = \View::make('forms.new-video', $data);
   }

}

Model(app/models/video.php):

<?php


class Video extends Eloquent {

    /**
     * The table used by this model
     *
     * @var string
     **/
    protected $table = 'videos';

    /**
     * The primary key
     *
     * @var string
     **/
    protected $primaryKey = 'video_id';

    /**
     * The fields that are guarded cannot be mass assigned
     *
     * @var array
     **/
    protected $guarded = array();

    /**
    *  Enabling soft deleting
    *
    *  @var boolean
    **/
     protected $softDelete = true;


    }

The view for my form is located at 'app\views\forms\new-video.blade.php'.

Am I not defining my 'create()' method properly or is a matter of not placing files in their correct location?

Upvotes: 0

Views: 1140

Answers (1)

damiani
damiani

Reputation: 7371

I believe you are missing the declaration of the $layout property in your controller, so it has no idea what view to use as the template:

/**
 * The layout that should be used for responses.
 */
protected $layout = 'layouts.master';

See http://laravel.com/docs/4.2/templates#controller-layouts.

Upvotes: 1

Related Questions