Laravel Form

Model Binding

// routes.php

	// route to show our edit form
	Route::get('nerd/edit/{id}', array('as' => 'nerd.edit', function($id) 
	{
		// return our view and Nerd information
		return View::make('nerd-edit') // pulls app/views/nerd-edit.blade.php
			->with('nerd', Nerd::find($id));
	}));

	// route to process the form
	Route::post('nerd/edit', function() {
		// process our form
	});
	



	{{ Form::model($nerd, array('route' => 'nerd.edit', $nerd->id)) }}	

		
		{{ Form::label('name', 'Name') }}
		{{ Form::text('name') }}

		
		{{ Form::label('email', 'Email') }}
		{{ Form::email('email') }}		

		{{ Form::submit('Update Nerd!') }}

	{{ Form::close() }}

source: http://scotch.io/quick-tips/php-tips/laravel-php/laravel-form-model-binding

Form model binding and file upload

Form model binding can be done by declaring form open as

 {{ Form::model($product, array('route' => array('product.postedit', $product->id), 'files'=> true)) }}	

source: http://stackoverflow.com/questions/20688289/form-model-binding-and-file-upload

Laravel Admin Panel

Every laravel project maybe large scale or small scale needs a dedicated laravel admin which can handle its own tasks uniquely like CRUD Management , User Management , Groups Management , Login System , Registration System , Forgot Password , User Analytics (Current loggedin users,page views by user , on which page user is browsing , which component is getting much attention by user ) ,Cron jobs and so on.

http://kodeinfo.com/post/laravel-admin-panel-part-1-crud-management

https://github.com/shellprog/Lara-Admin

Laravel 4 : image resize package

Resize image with intervention/image

intervention/image: https://packagist.org/packages/intervention/image
install: http://image.intervention.io/getting_started/installation#laravel

composer.json: "intervention/image": "2.*"

> composer update

config/app.php:

In the $providers array add the service providers for this package.

'InterventionImageImageServiceProvider'

Add the facade of this package to the $aliases array.

'Image' => 'InterventionImageFacadesImage'

Now the Image Class will be auto-loaded by Laravel.

Basic example: http://image.intervention.io/

// open an image file
$img = Image::make('public/foo.jpg');

// now you are able to resize the instance
$img->resize(320, 240);

// and insert a watermark for example
$img->insert('public/watermark.png');

// finally we save the image as a new image
$img->save('public/bar.jpg');

 

Laravel 4 : There are no commands defined in the “bundle” namespace.

I am simply trying to install a laravel bundle.
But when I try something like:
php artisan bundle:install imageworkshop

I’ve got this error:
[InvalidArgumentException]
There are no commands defined in the “bundle” namespace.

The answer:
Laravel 4 doesn’t use Bundles. It uses packages that are distributed via Packagist and Composer

Packagist: https://packagist.org/search/?q=laravel%20image%20resize

So this site doesn’t fit to Laravel 4
http://bundles.laravel.com/bundles

Laravel : Populating a dropdown menu with database results

In order to populate a dropdown menu with all the records from the RecordCompany model, you can do the following, in your view:

{{ Form::select('company_id', RecordCompany::lists('company_name', 'id')) }}

Explanation of the code:

The Form::select methods creates a HTML select tag.
company_id is the name of the select tag.
The second parameter is the options for the select tag. The lists method in any model (RecordCompany in this case) generates an associative array containing the parameters passed to that method (id and company_name in this case) of all the records in the model’s database table.

If you want, you can also call the lists method from the controller and then pass the value to the view, like following:

In Controller

$company_lists = RecordCompany::lists('company_name', 'id');

return View::make(‘admin.record_new’, array(‘company_lists’ => $company_lists));

In View

{{ Form::select('company_id', $company_lists) }}

You can view the Laravel 4 documentation for generating a drop down list here:

http://laravel.com/docs/html#drop-down-lists

source: http://stackoverflow.com/questions/21937116/populating-a-dropdown-menu-with-database-results-in-laravel-4

Install Laravel application in 4 steps

If you download a Laravel application (e.g. from GitHub) this doen’t contain the Laravel framework and other bundles.
You can deploy it in few steps on your development pc.

1, Use this console command at  main folder:   > composer update

2, Set database connection : /app/config/database.php

3, Use this console command at  main folder:php artisan migrate

4, Than: php artisan db:seed