1. Go to this page and download the library: Download laraviet/commander library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Laracasts\Commander\CommanderTrait;
class JobsController extends \BaseController {
use CommanderTrait;
/**
* Publish the new job listing.
*
* @return Response
*/
public function store()
{
}
}
use Laracasts\Commander\CommanderTrait;
use Acme\Jobs\PostJobListingCommand;
class JobsController extends \BaseController {
use CommanderTrait;
/**
* Post the new job listing.
*
* @return Response
*/
public function store()
{
$this->execute(PostJobListingCommand::class);
return Redirect::home();
}
namespace Acme\Jobs;
use Laracasts\Commander\Laraviet\BaseArrayCommand;
class PostJobListingCommand extends BaseArrayCommand
{
}
namespace Acme\Jobs;
use Laracasts\Commander\CommandBus;
class JobSanitizer implements CommandBus {
public function execute($command)
{
// sanitize the job data
}
}
namespace Acme\Jobs;
use Laracasts\Commander\CommandHandler;
use Laracasts\Commander\Events\DispatchableTrait;
class PostJobListingCommandHandler implements CommandHandler {
use DispatchableTrait;
public function handle($command)
{
$job = Job::post($command->$data);
$this->dispatchEventsFor($job);
return $job;
}
}
namespace Acme\Jobs;
use Laracasts\Commander\Events\EventGenerator;
use Acme\Jobs\Events\JobWasPublished;
class Job extends \Eloquent {
use EventGenerator;
protected $fillable = ['title', 'description'];
public static function post($data)
{
// Persistence data
$job = static::create($data);
$job->raise(new JobWasPublished($job));
return $job;
}
}
$job->raise(new JobWasPublished($job));
namespace Acme\Jobs\Events;
use Acme\Jobs\Job;
class JobWasPublished {
public $job;
public function __construct(Job $job) /* or pass in just the relevant fields */
{
$this->job = $job;
}
}
Event::listen('Acme.Jobs.Events.JobWasPublished', function($event)
{
var_dump('Send a notification email to the job creator.');
});
namespace Acme\Listeners;
use Laracasts\Commander\Events\EventListener;
use Acme\Jobs\Events\JobWasPublished;
class EmailNotifier extends EventListener {
public function whenJobWasPublished(JobWasPublished $event)
{
var_dump('send an email');
}
}
namespace Acme\Bar;
class SubscribeUserCommand {
/**
* Constructor
*/
public function __construct()
{
}
}
namespace Acme\Bar;
use Laracasts\Commander\CommandHandler;
class SubscribeUserCommandHandler implements CommandHandler {
/**
* Handle the command.
*
* @param object $command
* @return void
*/
public function handle($command)
{
}
}
namespace Acme\Bar;
use Laracasts\Commander\Laraviet\BaseArrayCommand;
class SubscribeUserCommand extends BaseArrayCommand
{
}