Laravel Start with First App

As we discussed in installation step of laravel, After installation we start to make new apps. The steps are describes given below:

So…

  1. A request is send it means when a user enters a URL associated with your application.
  2. route associated with that URL maps the URL to a controller action with function name.
  3. That controller action leverages the necessary model(s) to retrieve information from the database, and then passes that data off to a view.
  4. And that view renders the final page.
  5. Building a sample application

First we needs to create migrations file using command like:

php artisan migrate:make create_users_table

The --table and --create options may also be used to indicate the name of the table, and whether the migration will be creating a new table:

php artisan migrate:make add_votes_to_user_table --table=users

php artisan migrate:make create_users_table --create=users

When we apply this command then creates a one file which postpix like create_users_table.php. You can change name it. Then needs to be create table defination insert there file and also write drop table code.


use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DemoTable extends Migration {
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::table('DemoTable', function(Blueprint $table)
		{
			$table->increments('id');
                        $table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('DemoTable', function(Blueprint $table)
		{
			Schema::drop('DemoTable');
		});
	}

}

Before migration, you should make a database name which is define database configure file. And make table name which is only make table. Then call below commands:

$ php artisan migrate

Laravel also includes a simple way to seed your database of migration file with default data  using seed classes. All seed classes are stored in app/database/seeds. Seed classes may have any name you wish, but probably should follow some sensible convention, such as UserTableSeeder, etc. By default, a DatabaseSeederclass is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.

The Controller

In Laravel, a type of object — such as a Demo, in this case — is referred to as a resource.

Since it’s so common to build applications around resources, you can generate a resource controller — a controller to handle all requests related to a resource — using another simple Artisan command:

Instead of defining all of your route-level logic in a single routes.php file, you may wish to organize this behavior using Controller classes. Controllers can group related route logic into a class name with define function name, as well as take advantage of more advanced framework features such as automatic dependency injection.

Controllers are typically stored in the app/controllers directory, and this directory is registered in the classmap option of your composer.json file by default. However, controllers can technically live in any directory or any sub-directory. Route declarations are not dependent on the location of the controller class file on disk. So, as long as Composer knows how to autoload the controller class, it may be placed anywhere you wish.

And, you may also specify a subset of actions to handle on the route:

Route::resource('photo', 'PhotoController',array('only' => array('index', 'show')));
Route::resource('photo', 'PhotoController',array('except' => array('create', 'store', 'update', 'destroy')));
Route::resource('photos.comments', 'PhotoCommentController');
Route::get('photos/popular', 'PhotoController@method');
Route::resource('photos', 'PhotoController');
Route::get('user/{id}', 'UserController@showProfile');

The controller method accepts two arguments. The first is the base URI the controller handles, while the second is the class name of the controller. Next, just add methods to your controller, prefixed with the HTTP verb they respond to:

class UserController extends BaseController {
    public function getIndex()
    {
        //
    }
    public function postProfile()
    {
        //
    }
    public function anyLogin()
    {
        //
    }
}

Passing Data To Views

// Using conventional approach
$view = View::make('greeting')->with('name', 'Steve');

// Using Magic Methods
$view = View::make('greeting')->withName('steve');

Passing A Sub-View To A View

Sometimes you may wish to pass a view into another view. For example, given a sub-view stored atapp/views/child/view.php, we could pass it to another view like so:

$view = View::make('greeting')->nest('child', 'child.view');
$view = View::make('greeting')->nest('child', 'child.view', $data);

 

Let's Think together, Say Something !