Skip to content

Instantly share code, notes, and snippets.

@bmitch
Forked from Exadra37/laravel-tips.md
Created January 5, 2015 17:01
Show Gist options
  • Save bmitch/80056d03363e99c35926 to your computer and use it in GitHub Desktop.
Save bmitch/80056d03363e99c35926 to your computer and use it in GitHub Desktop.

LARAVEL TIPS

Call Artisan Command from Controller, Repository or any other place in your App

<?php

/**
 * @author  Exadra37    <exadra37atgmailpointcom>
 * @since   2014/07/02
 */

// Illuminate\Support\Facades\Artisan;
// First parameter it is the command
// Second parameter is an array of commands arguments
Artisan::call("brainsocket:start", array('--port' => 8081));

// Inside of command class you don't need to use the facade
$this->call("brainsocket:start", array('--port' => 8081));

Call Api Internally

/**
 * @author  Exadra37    <exadra37atgmailpointcom>
 * @since   2014/07/02
 */

// call a route internally
$request = Request::create('/api/db/find/device/all.json?count=true', 'GET');

// We need to replace the input so that the query string will be available in facade Input
$request::replace($request->input());

// get the normal response from your controller as if if you have call it from the browser
$response = Route::dispatch($request)->getContent();

// Do whatever you need now with your $response
@bmitch
Copy link
Author

bmitch commented Jan 5, 2015

@Exadra37 - Found a minor typo...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment