Skip to content

Instantly share code, notes, and snippets.

@aebersold
Last active October 13, 2015 16:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save aebersold/4225971 to your computer and use it in GitHub Desktop.
Save aebersold/4225971 to your computer and use it in GitHub Desktop.
laravel cheat-sheet

Laravel Cheat-Sheet

Common usage

View::share('user', $user); Makes $user available to all views.

URI::segment(1); First segement uf an URL (eg. site.com/de/hello = de).

Config::get('file.var') Access config var/array.

Request::server('http_user_agent') Returns header fields.

return Redirect::to('admin/view'); Redirect to URL admin/view.

Config::set('application.language', $lang); Set application langague

Session::put('name', 'content'); Store sessions/cokies.

Hash::make($pass); Generate a hashed string.

Hash::check('string', $user->password) Checks string against field. Returns true/false.

Str::slug($str, $separator = '-') Generate URL-safe strings.

Router

Route::get('login','login@form'); route '/login', uses controller login, method form.

Route::get();, Route::post();, Route::any(); Requesting methods.

Controllers

if(Request::ajax()) Returns true if AJAX request.

return Response::json($data); Responses $data as JSON-String.

return View::make('home.index'); Returns view from folder home, file index.

Forms

Input::get('name'); get requests

e($var) escape $var.

Templates

@yield('content') Section content, available via @section

URL::current(); Current URL, including language. w/o query string.

URL::full(); Full URL w/ query string.

URL::to_asset('img/test.jpg') Link file in public folder. Echos full URL.

@if(Request::env() == 'local') Check if environnement = local.

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