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

Laravel News - News and information about Laravel Bienvenue sur Laravel France 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. <!

CRUD Operations in laravel 4 with mysql Sometimes we need to create a CRUD operation for our projects, Create, Read, Update and Delete tables in database using Laravel. I admit it, Laravel is a complex framework, but once you understand how to manage it, it become easy and powerful framework for PHP development. At the end of this tutorial, you should be able to create a basic application where you can add, edit, delete and list Books. Create a project called bookshop Before getting started, be sure to configure a database connection in app/config/database.php Just modify mysql connection. 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'library', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), Using artisan, lets create a table and after that we will migrate to mysql database. 4. The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. <? 5. <? 6. 7. 8. <? 9.

The PHP framework for web artisans. Where To Start Learning a new framework can be daunting, but it's also exciting. To smooth your transition, we've attempted to create very clear, concise documentation for Laravel. Here are some recommendations for what to read first: After reading through these documents, you should have a good grasp on basic request / response handling in Laravel. Next, you may wish to read about configuring your database, the fluent query builder, and the Eloquent ORM. Laravel Philosophy Laravel is a web application framework with expressive, elegant syntax. Laravel aims to make the development process a pleasing one for the developer without sacrificing application functionality. Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications.

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:

Creating forms in Laravel 4 One of the very basic requirements of all online applications is that the user should be able to enter data. Web forms are the most commonly used methods for entering data into an application and so they are a fundamental thing that you need to get right. Laravel is a framework that aims to make developing and maintaining web applications as easy as possible. One of the ways this is achieved is by having an excellent Form class that makes creating and interacting with forms extremely easy. A lot of other frameworks seem to make working with forms much harder then they need to be. So let’s look at building Laravel forms! Creating forms for Cribbb If you remember back to when we were building out the Controller methods of the User resource, the create and edit methods are used to display a form so the user can create or edit a record in the system. Both of these methods simply return a View to the browser. This will create the following HTML output: Methods Routes and Methods Params Files Labels

Laracasts | Screencasts 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 4 E-Commerce — Laravel 4 Tutorials Introduction One of the benchmarks of any framework is how well it fares in the creation of an e-commerce application. Laravel 4 is up to the challenge; and today we’re going to create an online shop. While much effort has been spent in the pursuit of accuracy; there’s a good chance you could stumble across a curly quote in a code listing, or some other egregious errata. I have also uploaded this code to Github. This assumes, of course, that you know how to do that sort of thing. If you spot differences between this tutorial and that source code, please raise it here or as a GitHub issue. Note On Sanity There is no way that an e-commerce platform, built in 30 minutes, can be production-ready. This tutorial is a guide, an introduction, a learning tool. Getting Started In this tutorial; we will create a number of database objects, which will later be made available through API endpoints. Installing Laravel 4 AngularJS Bootstrap Stripe <? <!

PHP Coding Guidelines | PHP Developer These are the guidelines that I follow when writing my PHP scripts, unless a coding standard already exists for the project I’m working on. It can be helpful to have something like this if you’re working on a joint project. N.B. These are only the guidelines that I personally chose to follow for the code I write. This is not an indication that any other coding styles, guidelines or standards are wrong. Feel free to use this document as a template to manage your own coding guideline and change whatever you wish as you see fit. Why are guidelines important? First of all, let’s make one point clear: it doesn’t matter what your guidelines are, so long as everyone understands and sticks to them. It cannot be emphasised enough that guidelines are only useful if they are followed. Editor settings Tabs v. spaces Ahh, the endless debate of tabs v. spaces. Linefeeds The three major operating systems (Unix, Windows and Mac OS) use different ways to represent the end of a line. Naming conventions N.B.

Laravel: my first framework. Chapter 2 - Getting started for Development with Laravel - Maks Surguy's blog on PHP and Laravel The following content is the second chapter of my new e-book titled “Laravel: my first framework“. This writing is copyright by Maksim Surguy. Unauthorized copy and distribution of this material is prohibited. This chapter covers Installing Laravel with ComposerMeeting Artisan: the command line interfaceUnderstanding structure of a Laravel applicationCreating a website with Laravel Getting started with some PHP frameworks could be a hard and painstaking process with a steep learning curve. Prerequisites This chapter assumes that you have Apache, PHP 5.3.7 or greater with MCrypt extension installed and database engine like MySQL already installed and set up. 2.5 Development overview In the previous chapter you have learned that Laravel comes pre-configured to work out of the box. Don’t worry if some of these terms are not familiar to you yet, we will be giving proper attention to all of them throughout the book. A note on design patterns 2.6 Meeting Composer 2.7 Installing Laravel Please note

Related: