Topics

Laravel Documentation

For learn larvel Favorite site LInk

https://laravel.com/
https://laravelcollective.com/
http://laravel-recipes.com/

AppServiceProvider.php file and inside the boot method set a default string length:

use Illuminate\Support\Facades\Schema;
public function boot()
{
    Schema::defaultStringLength(191);
}
		

Start for Image

Composer Installation

The best way to install Intervention Image is quickly and easily with Composer.

References : intervention Image

To install the most recent version, run the following command.

 $ composer require intervention/image
			

Now your composer.json has been updated automatically and you're able to require the just created vendor/autoload.php file to PSR-4 autoload the library.

The next step is to decide, if you want to integrate Intervention Image into the Laravel framework. If you want to use the library with Laravel, just skip the following step and continue with the description of Laravel Integration.

Integration in Laravel

Intervention Image has optional support for Laravel and comes with a Service Provider and Facades for easy integration. The vendor/autoload.php is included by Laravel, so you don't have to require or autoload manually. Just see the instructions below.

After you have installed Intervention Image, open your Laravel config file config/app.php and add the following lines.

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

Intervention\Image\ImageServiceProvider::class
			

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

'Image' => Intervention\Image\Facades\Image::class
			

Example for image

if($request->hasFile('images')){
  $image = $request->file('images');
  $filename = time().'.'.$image->getClientOriginalExtension();
  $location = public_path('images/'.$filename);
  Image::make($image)->resize(100,200)->save($location);
  $course->images = $filename;
 }
			

make a Controller example



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Category;

class categoryController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $category = new Category;
        $data = $category->all();
        return view('category/index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('category/create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $category = new Category;
        $category->name = $request->name;
        $category->save();

        return redirect()->route('category.show',$category->id);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $category = new Category;
        $data = $category->find($id);
        return view('category/show',compact('data'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $category = new Category;
        $data = $category->find($id);
        return view('category/edit',['data'=>$data,'id'=>$id]);

    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $category = new Category;
        $this->validate($request,array(
            'name'=>'required'));


        $data = $category->find($id);

        //echo $request->name;
        $data->name = $request->input('name');
        $data->save();

        return redirect()->route('category.index');

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $category = new Category;
        $data = $category->find($id);
        $data->delete();
        return redirect()->route('category.index');
    }
}

			

make a Example Model


namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
	protected $table="category";

    //protected $fillable = ['name'];

    //protected $hidden = ['created_at'];

    
}
			

make a Example Form

@if($errors->any())
    <div class="alert alert-danger" style="margin-top: 50px;">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif			    
			    
			 
{!! Form::open(['route'=>'post.store','method'=>'post','files'=>true]) !!}

  <div class="form-group">
    {!! Form::label('title','Post title here')!!}
   {!! Form::text('title',null,['class'=>'form-control'])!!}
  </div>


  <div class="form-group">
    {!! Form::label('description','Post Description here')!!}
    {!! Form::textarea('description',null,['class'=>'form-control'])!!}
  </div>


    <div class="form-group">
    {!! Form::label('slug','slug title here')!!}
    {!! Form::text('slug',null,['class'=>'form-control'])!!}
  </div>


   <div class="form-group">
    {!! Form::label('category','Select Category here')!!}
    {!! Form::select('category',$catData,null,['class'=>'form-control'])!!}
  </div>


    <div class="form-group">
   {!! Form::label('post_image','Select Images Here...')!!}
   {!! Form::file('post_image')!!}
  </div>



  {!! Form::submit('Public Post',['class'=>'btn btn-primary'],['style'=>'margin-top:30px;'])!!}
  {!! Form::close() !!}
			

Show Session Message

// use Session;
Session::flash('success','Well done ! add your data successfully');


@if(Session::has('success'))
    <div class="alert alert-success" style="margin-top: 50px;">
        {{ Session::get('success') }}
    </div>
@endif
			

Example for Route

Route::get('/', 'homeController@index');
Route::get('contact', 'homeController@contact');
Route::get('about', 'homeController@about');
Route::resource('post','postController');
Route::resource('category','categoryController');
Route::get('blog','blogController@index');

Route::get('blog/{slug?}',['as'=>'blog.single','uses'=>'blogController@getData']);

//authentication
//Route::get('auth/login','Auth\LoginController@getLogin');
Route::get('auth/login','Auth\LoginController@showLoginForm');
Route::post('auth/login',['as'=>'login.test','uses'=>'Auth\LoginController@login']);
Route::get('auth/logout','Auth\LoginController@logout');

//register
Route::get('auth/register','Auth\RegisterController@showRegistrationForm');
Route::post('auth/register',['as'=>'register.store','uses'=>'Auth\RegisterController@register']);


			

Example for Validation

        $course = new Course();
        $this->validate($request,[
            'name'=>'required|max:225',
            'description'=>'required|max:3000',
            'post_count_for_free'=>'required|max:3000',
            'categoryid'=>'required|max:3000',
            ]);

        $course->name = $request->name;
        $course->description = $request->description;
        $course->post_count_for_free = $request->post_count_for_free;
        $course->categoryid = $request->categoryid;
			

Login Blade Template


@extends('layout')

@section('title','Login page')

@section('content')

<h3>Login Page</h3>
<hr>
<div class="row">
<div class="col-md-7"> 
@if($errors->all())
@foreach($errors->all() as $error)
	<div class="alert alert-danger" role="alert">
		{{ $error }}
	</div>

@endforeach

@endif


{!! Form::open(['route'=>'login.test','method'=>'post']) !!}

  <div class="form-group">
   {!! Form::label('email','username here')!!}
   {!! Form::text('email',null,['class'=>'form-control'])!!}
  </div>


    <div class="form-group">
   {!! Form::label('password','password here')!!}
   {!! Form::password('password',['class'=>'form-control'])!!}
  </div>

  {!! Form::submit('Sign In',['class'=>'btn btn-primary'],['style'=>'margin-top:30px;'])!!}


{!! Form::close() !!}

</div>
</div>

@endsection
			

Register Blade Template

@extends('layout')

@section('title','Register page')

@section('content')

<h3>Register Page</h3>
<hr>
<div class="row">
<div class="col-md-7">

@if($errors->all())
@foreach($errors->all() as $error)
	<div class="alert alert-danger" role="alert">
		{{ $error }}
	</div>

@endforeach

@endif


{!! Form::open(['route'=>'register.store','method'=>'post']) !!}

  <div class="form-group">
   {!! Form::label('name','Your Name here')!!}
   {!! Form::text('name',null,['class'=>'form-control'])!!}
  </div>


  <div class="form-group">
    {!! Form::label('email','email here')!!}
   {!! Form::email('email',null,['class'=>'form-control'])!!}
  </div>

    <div class="form-group">
    {!! Form::label('password','Password here')!!}
   {!! Form::password('password',['class'=>'form-control'])!!}
  </div>


   <div class="form-group">
    {!! Form::label('password_confirmation','Confirm Password here')!!}
   {!! Form::password('password_confirmation',['class'=>'form-control'])!!}
  </div>




	{!! Form::submit('Sign Up',['class'=>'btn btn-primary'],['style'=>'margin-top:30px;'])!!}


{!! Form::close() !!}

</div>
</div>


@endsection
			

Data Base Relation

	public function category(){
	return Category::where('id',$this->cid)->first()->name;
	}
	//using $article->category();
			    
	// other way
			    
	public function user(){
		return $this->belongsTo('App\Category','cid','id');
	}
	//User model
	//using $article->user->name;
			    
	//formate
	return $this->belongsTo('User','foreign key','local key');
			

Share Data Any View

			    
    //go to app/Providers/AppServiceProvider page 
    use View;
    public function boot()
    {
        $header = Category::all();

        View::share('header',$header);

        Schema::defaultStringLength(191);
    }