Skip to main content

Getting Started with Laravel 5.4 with sample CURD

/*
|-----------------------------------------------------------------------------
| Getting Started with Laravel 5.4
|-----------------------------------------------------------------------------
|
| Laravel 5.4 has more features and Laravel is a free, open-source PHP web 
| framework, created by Taylor Otwell and intended for the development of 
| web applications following the model–view–controller (MVC) architectural pattern.
|
*/

Database: Migrations

#Generating Migrations
----------------------------
To create a migration, use the make:migration Artisan command:
Syntax:
php artisan make:migration create_users_table

The new migration will be placed in your database/migrations directory. Each migration file name contains a timestamp which allows Laravel to determine the order of the migrations.
Example:
vagrant@homestead:~/sample$ php artisan make:migration create_student_table
   Created Migration: 2017_08_01_044007_create_student_table
--------------------
#Running Migrations
--------------------
To run all of your outstanding migrations, execute the migrate Artisan command:

Syntax:
php artisan migrate

If you are using the Homestead virtual machine, you should run this command from within your virtual machine.

#Tables

#Creating Tables

To create a new database table, use the create method on the Schema facade. The create method accepts two arguments. The first is the name of the table, while the second is a Closure which receives a Blueprint object that may be used to define the new table:

Schema::create('users', function (Blueprint $table) {
$table->increments('id');
});
Of course, when creating the table, you may use any of the schema builder's column methods to define the table's columns.

Eloquent: Getting Started

#Defining Models
------------------
To get started, let's create an Eloquent model. Models typically live in the app directory, but you are free to place them anywhere that can be auto-loaded according to your composer.json file. All Eloquent models extend Illuminate\Database\Eloquent\Model class.
The easiest way to create a model instance is using the make:model Artisan command:
Syntax:
php artisan make:model Models/Student

Example:
vagrant@homestead:~/sample$ php artisan make:model Models/Student
 Model created successfully.

Controllers

#Resource Controllers
----------------------
Laravel resource routing assigns the typical "CRUD" routes to a controller with a single line of code. For example, you may wish to create a controller that handles all HTTP requests for "photos" stored by your application. Using the make:controller Artisan command, we can quickly create such a controller:
Syntax:
php artisan make:controller StudentController --resource

This command will generate a controller at app/Http/Controllers/StudentController.php. The controller will contain a method for each of the available resource operations.

Next, you may register a resourceful route to the controller:

Route::resource('Student', 'StudentController');
This single route declaration creates multiple routes to handle a variety of actions on the resource. The generated controller will already have methods stubbed for each of these actions, including notes informing you of the HTTP verbs and URIs they handle.

Example:
vagrant@homestead:~/sample$ php artisan make:controller StudentController --resource
Controller created successfully.

Validation

#Form Request Validation
------------------------
#Creating Form Request
-----------------------
For more complex validation scenarios, you may wish to create a "form request". Form requests are custom request classes that contain validation logic. To create a form request class, use the  make:request Artisan CLI command:
Syntax:
php artisan make:request StoreBlogPost

The generated class will be placed in the app/Http/Requests directory. If this directory does not exist, it will be created when you run the make:request command.

Example:
vagrant@homestead:~/student$ php artisan make:request StudentRequest
 Request created successfully.

LaravelCollective

#Forms & HTML
---------------
#Installation
--------------
Begin by installing this package through Composer. Edit your project's composer.json file to require laravelcollective/html.
Syntax:
composer require "laravelcollective/html":"^5.4.0"

Example :
vagrant@homestead:~/sample$ composer require "laravelcollective/html":"^5.4.0"

fig:Laravel Collective installing via composer

Next, add your new provider to the providers array of config/app.php:

  'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
  ],
Finally, add two class aliases to the aliases array of config/app.php:

  'aliases' => [
    // ...
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,
    // ...
  ],


Routing

The most basic Laravel routes simply accept a URI and a Closure, providing a very simple and expressive method of defining routes:

Syntax:

Route::get('foo', function () {
    return 'Hello World';
});

Example:
Route::group([ 'middleware' => 'auth'], function(){
Route::resource('student', 'StudentController');
});

Comments

Popular posts from this blog

vagrant up not working windows 10 | Stderr: VBoxManage.exe: error: Failed to get device handle and/or partition

 vagrant up not working windows 10 If you get an error message during  vagrant up  or when starting a VirtualBox machine, telling you that VT-x is not available, a reason may be that you have enabled Hyper-V on your Windows 10 machine: VirtualBox and Hyper-V cannot share the VT-x CPU: $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'thesteve0/openshift-origin' is up to date... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 8443 (guest) => 8443 (host) (adapter 1) default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command an

Create a Plugin in the in Windows for Processmaker 3.0

**************************************************************************   To Create a Plugin in the in Windows for Processmaker ************************************************************************** Now let us create the plugin using windows os for the processmaker. The main Steps to Plugins cannot be created on Windows servers, because Windows does not support symbolic links; however, there is an experimental script for Windows servers available at <INSTALL-DIRECTORY>/workflow/engine/gulliver-win.bat which can be tested. http://wiki.processmaker.com/3.0/Plugin_Development The steps given below as a step by step please follow this any query just post commands. Step :1 ============ C:\Bitnami\processmaker-3.1-1\apps\processmaker\htdocs\workflow\engine>gulliver-win.bat new-plugin deleteCases using DSN Connection The plugin deleteCases exists in this file C:\Bitnami\processmaker-3.1-1\apps\pr ocessmaker\htdocs\workflow\engine\plugins\deleteCases\class.deleteCas

Extjs Dynamically Update Panel content html

To add html to an EXTJS panel after it has been rendered you can use. Ext.getCmp(''the I.D of your panel'').body.update(''your HTML"); new Ext.Panel({             border: false,             frame: false,             width: 200,             region: 'west',             id: 'panel-id',             bodyStyle: "background: #fff"         } //and I want in another module change panel content... so use this: Ext.getCmp('panel-id').body.update('html content for example'); Example 2: {     xtype: 'panel',     title: 'Testing',     id: 'taskpanel',     html: 'testing' } //to update the panel content. For html use body.update 3 Ways to render HTML inside of a ExtJS container Ext.onReady(function() {     new Ext.Panel({         renderTo: Ext.getBody(),         title: '3 Ways to render HTML inside of a ExtJS container',         items: [{             html: &quo