Route::post('start', 'StartController@execute');
<?php
use Illuminate\Http\Request;
class StartController extends Controller
{
protected $commands = [
'hello' => HelloCommand::class,
];
public function execute(Request $request)
{
$command = $request->get('command');
if ($command && is_string($command) && array_key_exists($command, $this->commands)) {
return with(new $this->commands[$command])->execute();
}
return response('Command not found', 404);
}
}
public function user()
{
return $this->belongsTo(User::class);
}
Post::with('user')->orderBy('publish_at', 'desc')->get();
$posts = DB::table('posts')->select(DB::raw('posts.*, users.username'))
->join('users', 'posts.user_id', '=', 'users.id')
->orderBy('publish_at', 'desc')->get();
$('#form').on('submit', function (e) {
var file = $('input[type=file]')[0].files[0],
data = new FormData($(this)[0]);
if (file == null) {
alert("File is empty");
return false;
}
e.preventDefault();
submit(data);
});
function submit(data) {
$.ajax({
...
data: data,
method: "POST",
contentType: false,
processData: false,
...
});
}