background preloader

Laravel Cheat Sheet

Laravel Cheat Sheet

Easy Wins For More Performant PHP Introduction Making your website more performant can require a lot of layers. From setting up a reverse-proxy cache with Varnish to configuring a group of load balancers, there are many well-documented options. What if you're just starting out? This article will explore easy wins for more performant PHP you can implement either as standard practices for your development team or principles you can retrofit for an existing application. At Minimum, Upgrade to PHP 5.4 As of this article, the latest version of PHP is currently 5.5.5. If PHP 5.5.5 isn't an option, you MUST minimally begin with PHP 5.4. Running Drupal? Autoload Autoloading involves including classes in files that are used throughout your application without having to manually reference the file paths. We can use Composer to achieve this result. Composer has been covered in past articles for dependency management. For example, if you have classes in a src folder in PSR-0 format: Reduce Memory Usage in Code Profile OpCode Caching Summary

Dimensi TutupBotol: Basic Routing in Laravel 5.1 I'm using laravel version 5.1.10 in this post. If you still don't install it, you can see about my laravel installation process here and here. Aaand...I'm using XAMPP for viewing the laravel default page. Okieee... Default routes code is shown below : Well.. Sooo... the "/" in get function is like a directory that we requested on the web browser and return value of this get function is the content of page that is shown in our browser. This code will result : Next, let's change the slash sign of get function as follow : Now when opening the page, we have to add ~/hyosoka at the end of the url page because I'm changing the '/' to 'hyosoka' so the url now is I hope above examples give you a good sense about how this route works on laravel hehehe... The result is : Ummm... So we need to add a simple handler if user doesn't put itachi at the end of url page. The result if itachi == null or user didn't put the itachi at the end of url page : Soo...

The Best Laravel and PHP Screencasts Browsing Most Recent Laravel Tricks Check Member's/ User's Online or Offline Status Introduction The following piece of code will calculate the last visited time of a Member/User and calculate the time difference with the current time. And if the Member/User's last visited time is greater than 10 minutes then that will be considered OFFLINE status, otherwise ONLINE. Background I was just searching for a time difference code in Bakery but couldn't find any simple code. Using the code There are only three steps to follow. "I am assuming that you have a table named MEMBER (you can customize it according to your requirements)". Make a field last_visit (DATETIME) in MEMBER table.For app controller: Simply use the following code in your .ctp file according to your demand. <!

Udemy - Everything About Laravel Description Udemy - Everything About LaravelMP4 | Video: 1280x720 | 57 kbps | 48 KHz | Duration: 9 Hours | 1.38 GBGenre: eLearning | Language: EnglishStep by step walkthrough everything about Laravel's fundementals, routing, filters, database, templating with app making Introducing Laravel, a standout PHP framework that helps developers build standout applications. What is Laravel? readmoreTopics include: Installing LaraveHandle routing requestsFilter routes, and apply controllersOutputting code and working with Laravel's advanced templating engine, BladeIntegrate a functional database with Schema BuilderQuery data with Eloquent ORM, and keep your schema up to date with migrations.All of these tutorials culminate in the final chapters, where you'll learn how to build your first app and deploy it on the web. I will issue hands-on practice challenges along the way to help you test your knowledge. What are the requirements? Over 57 lectures and 8 hours of content! Search More...

Jouer avec Composer Pourquoi utiliser tout un Framework comme Laravel lorsqu’on a une tâche toute simple à effectuer ? On peut évidemment utiliser la version allégée Lumen. Mais on peut aussi tout simplement faire ses courses dans Packagist. Mais d’abord qu’est-ce que Composer ? Si vous utilisez Laravel vous connaissez déjà Composer et il est installé sur votre ordinateur. Allons faire notre marché sur Packagist. un routeurun convertisseur Markdown Voyons un peu ce que nous trouvons… Une recherche avec « route » donne : On voit que le plus utilisé est nikic/fast-route, mais on voit aussi que league/route est basé sur ce package. Voyons maintenant pour Markdown : Là sans hésiter je choisis michelf/php-markdown. Maintenant que les packages sont choisis comment les installer ? Commençons par préparer un dossier sur un serveur pour accueillir notre application. On attend un petit peu et on obtient ce genre de chose : Voyons le résultat : On se retrouve avec pas mal de choses ! On a enfin un dossier composer :

Accessing Incoming PUT Data from PHP Recently I started writing a REST service. I began in the usual way, writing a php script, calling it with a GET request, accessing the variables using the PHP superglobal variable $_GET. I wrote code to handle a POST request and used the variables I found in $_POST. Then I tried to write a PUT request. PHP doesn't have a built-in way to do this, and at first I was a little confused as to how I could reach this information. file_get_contents(" The above line provided me with a query string similar to what you might see on the URL with a GET request. key/value pairs separated by question marks. parse_str(file_get_contents(" This loads the variable $post_vars with the associative array of variables just like you'd expect to see from a GET request. Simple Example Its a bit of a contrived example but it shows use of the REQUEST_METHOD setting from the $_SERVER variable to figure out when we need to grab the post vars. Via GET: Via PUT:

Installation Installation Server Requirements The Laravel framework has a few system requirements. Of course, all of these requirements are satisfied by the Laravel Homestead virtual machine: PHP >= 5.5.9OpenSSL PHP ExtensionPDO PHP ExtensionMbstring PHP ExtensionTokenizer PHP Extension Installing Laravel Laravel utilizes Composer to manage its dependencies. Via Laravel Installer First, download the Laravel installer using Composer: composer global require "laravel/installer=~1.1" Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable can be located by your system. Once installed, the simple laravel new command will create a fresh Laravel installation in the directory you specify. laravel new blog Via Composer Create-Project You may also install Laravel by issuing the Composer create-project command in your terminal: composer create-project laravel/laravel --prefer-dist Configuration Basic Configuration Directory Permissions Application Key Additional Configuration Pretty URLs

PHP: Reflection - Manual Here is a code snippet for some of us who are just beginning with reflection. I have a simple class below with two properties and two methods. We will use reflection classes to populate the properties dynamically and then print them:<?phpclass A{ public $one = ''; public $two = ''; //Constructor public function __construct() { //Constructor } //print variable one public function echoOne() { echo $this->one."\n"; } //print variable two public function echoTwo() { echo $this->two." 20 All Too Common Coding Pitfalls For Beginners Regardless of our current skill level, we all were beginners at one point in time. Making classic beginner mistakes comes with the territory. Today, we've asked a variety of Nettuts+ staff authors to chime in with their list of pitfalls and solutions - in a variety of languages. Learn from our mistakes; don't do these things! JavaScript Tips 1 - Unnecessary DOM Manipulation The DOM is slow. This code actually modifies the DOM 100 times, and unnecessarily creates 100 jQuery objects. 100! As noted above, with this technique, we touch the DOM only once, which is an improvement, but it also relies on string concatenation to build a large string. When building large strings, storing each piece of the string as an item within an array element and calling join() is arguably more elegant than string concatenation. 2 - Inconsistent Variable & Function Names in JavaScript It wouldn't make sense to add another variable, called Something. 3 - Use hasOwnProperty() in for...in Loops 5 - Event Binding

Laravel Archives | Dunebook Category - Laravel Laravel 4 : chapitre 13 : Les bases de données 1/3 – Laravel Nous allons à présent aborder un aspect important avec a gestion des bases de données. Laravel 4 est bien équipé dans ce domaine, comme nous allons le voir. Vous pouvez accéder à des bases : MySQL, SQLite, SQL server et PostgreSQL. Configuration La configuration est simple et se passe dans le fichier app/config/database.php. Par défaut on a mysql, mais vous pouvez aussi mettre sqlite, pgsql ou sqlsrv. J’ai défini une base nommée laravel pour les tests. Migration Laravel possède un outil bien pratique pour gérer la structure d’une base de données : migration. Et plus précisément ses paramètres utilisables : Commençons par créer une migration : Bon apparemment tout c’est bien passé mais où elle est cette migration ? Un fichier a été créé avec un nom composé d’un timestamp et du nom que nous avons donné à la migration. On y trouve une classe CreateEssences qui hérite de la classe Migration. Le Schema builder La syntaxe est si simple qu’elle se passe presque de commentaires. Et la suite ? .

Related: