Topic: Laravel

Laravel Pivot Tables Tutorial Example 0

Laravel Pivot Tables Tutorial Example

Today, We want to share with you Laravel Pivot Tables Tutorial Example.In this post we will show you Laravel multiple pivot table relationships, hear for Laravel 5.7 Role Management with Pivot Models we will give you demo and example for implement.In this post, we will learn about LARAVEL MANY-TO-MANY RELATIONS using Pivot Tables with an example.

Laravel Pivot Tables Tutorial Example

There are the Following The simple About Laravel Pivot Tables Tutorial Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Pivot Tables Example in Laravel, so the LARAVEL MANY-TO-MANY RELATIONS using Pivot Tables for this example is following below.

Pivot table — is a table used for Join or connecting Laravel relationships between two tables.

Working with pivot table(many-to-many) relationship in Laravel with Example

$product->types()->sync([1, 2, 3]) ;

If laravel Pivot table have some additionls columns add as well as we want to retrives them then we have to identify in your laravel model while defining the pivot table(many-to-many) relationship.

return $this->belongsToMany('Product')->withPivot('details');

Custom Pivot Table Models

here see full example of the Laravel custom pivot table

I have three tables :

  • fruites (I call it “Product”)
  • Product Category (I call it “Category)
  • Product Supplay (I call it “Supplay”)

My relationship :

  • Product has many Category (duplex fruites)
  • Product has many Supplay
  • Category has many Product
  • Category has many Supplay
  • Supplay has one Category
  • Supplay has one Product

class Product extends Model
{
    public function CategoryProducts(){
        return $this->hasMany('App\Models\Company\CategoryProduct');
    }

    public function Supplays()
    {
        return $this->hasManyThrough('App\Models\Company\Supplay','App\Models\Company\CategoryProduct', 'Category_id', 'Category_Product_id');
    }
}

class Category extends Model
{
    public function ProductCategorys()
    {
        return $this->hasMany('App\Models\Company\CategoryProduct');
    }

}

class CategoryProduct extends Model
{

    protected $table = 'Category_Product';

    public function Product(){
        return $this->belongsTo('App\Models\Company\Product');
    }

    public function Category(){
        return $this->belongsTo('App\Models\Company\Category');
    }

    public function Supplays()
    {
        return $this->hasMany('App\Models\Company\Supplay','Category_Product_id');
    }
}

class Supplay extends Model
{

    public function type(){
        return $this->belongsTo('App\Models\Company\Type');
    }

    public function CategoryProduct(){
        return $this->belongsTo('App\Models\Company\CategoryProduct','Category_Product_id');
    }

}
[/php

[php]
$fruites = Product::with('CategoryProducts','CategoryProducts.Category', 'Supplays')->first();
dd($fruites->Supplays);
foreach($fruites->CategoryProducts as $CategoryProduct){
    dd($CategoryProduct->Category);
}
[/php

[php]
$fruitess = Product::with('CategoryProducts','CategoryProducts.Category', 'Supplays')->withCount('Supplays')->get();

foreach($fruitess as $fruites){
    dd($fruites->Supplays_count);
    dd($fruites->Supplays); //direct Supplays for each fruites
    foreach($fruites->CategoryProducts as $CategoryProduct){
        dd($CategoryProduct->Category);
    }
}    

laravel pivot table migration

Create Laravel a new migration

php artisan make:migration create_alpha_beta_table --create --table=alpha_beta

Example: laravel pivot table

//get user by id
$user = App\User::find(1);

//get roles of this user
foreach ($user->roles as $role) {

  //pivot attribute returns a model which represent user_role table
  echo $role->pivot->created_at;

}
[/php

<p>create a Laravel class by extending pivot</p>
[php]
class Product extends Model
{
    /**
     * The users that belong to the role.
     */
    public function Cats()
    {
        return $this->belongsToMany('App\Cat')->using('App\Cat_Product');
    }
}

class Cat extends Model
{
    /**
     * The users that belong to the role.
     */
    public function Products()
    {
        return $this->belongsToMany('App\Product')->using('App\Cat_Product');
    }
}

class Cat_Product extends Pivot
{
    //
}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Pivot Tables Tutorial Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Laravel 5.6 Server Side Validation Example 0

Laravel 5.6 Server Side Validation Example Using Resource Controller

Today, We want to share with you Laravel 5.6 Server Side Validation Example Using Resource Controller.In this post we will show you server side api validation in laravel 5.7, hear for Laravel 5.7 Validation With Custom Rules Example From Scratch we will give you demo and example for implement.In this post, we will learn about Request based form validation with Laravel 5.7 with an example.

Laravel 5.6 Server Side Validation Example Using Resource Controller

There are the Following The simple About Laravel 5.6 Server Side Validation Example Using Resource Controller Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel Form Validation- Server Side form validation, so the some Server side Validation for this example is following below.

Laravel 5.7 Server side Validation Example

resources/views/product/create.blade.php

Simple Create View Blade file For Server Side Laravel validation in Resource Controller

<form action="{{ route('product.store') }}" id="addproduct" method="POST">
    <input name="_token" type="hidden" value="{{ csrf_token() }}">
    <input type="hidden" name="user_id" value="{{ Auth::id() }}">
    <input type="hidden" name="add_product_form" value="1">
    <div class="modal-body">
        <div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
            <label class="control-label">product Name</label>
            <input type="text" class="form-control" name="name" value="{{Request::old('name')}}">
            @if ($errors->has('name'))
                <span class="help-block"><strong>{{ $errors->first('name') }}</strong></span>
            @endif
        </div>
        <div class="form-group {{ $errors->has('price') ? ' has-error' : '' }}">
            <label class="control-label">product price</label>
            <input type="number" class="form-control" name="price" value="{{Request::old('price')}}">
            @if ($errors->has('price'))
                <span class="help-block"><strong>{{ $errors->first('price') }}</strong></span>
            @endif
        </div>
        <div class="form-group {{ $errors->has('qty') ? ' has-error' : '' }}">
            <label class="control-label">product Age</label>
            <input type="number" class="form-control" name="qty" value="{{Request::old('qty')}}">
            @if ($errors->has('qty'))
                <span class="help-block"><strong>{{ $errors->first('qty') }}</strong></span>
            @endif
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-info" type="submit">Add</button>
        <button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
    </div>
</form>

app/Http/Controllers/ProductController.php

public function store()
    {
        $rules = array(
            'name' => 'required|string|max:255',
            'price' => 'required|is_integer()',
            'qty' => 'required|is_integer()'
        );
        $params = $request->all();
        $validator = Validator::make($params, $rules);
        if ($validator->fails()) {
            $request->merge(array('add_product_form' => 1));
            //print_r($request->all());die('jjj');
            $input['add_product_form'] = '1';
            return redirect('product.create')
                        ->withErrors($validator)
                        ->withInput();
        } else {

            Product::create($request->all());

            flash()->success('The product has been created successfully.');

            return redirect()->route('product.index');  
        }
        
    }

Example 2 : Laravel Form Validation- Server Side form validation

Defining Routes

Route::get('sell', function(){
    return view('sell');
});
Route::post('sell', '[email protected]');

Creating Sell Form

<!DOCTYPE html>
<html>
<head>
<title>Get Product Online</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<form class="form-horizontal">
<fieldset>

<!-- Form Name -->
<legend>Fill the form to sell</legend>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>  
<div class="col-md-4">
<input id="name" name="name" type="text" placeholder="Your Product Full Name" class="form-control input-md">

</div>
</div>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="product_code">product_code</label>  
<div class="col-md-4">
<input id="product_code" name="product_code" type="text" placeholder="P0001235" class="form-control input-md">

</div>
</div>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="productminmax">productminmax</label>  
<div class="col-md-4">
<input id="productminmax" name="productminmax" type="text" placeholder="+91" class="form-control input-md">

</div>
</div>

<!-- Multiple Radios (inline) -->
<div class="form-group">
<label class="col-md-4 control-label" for="producttype">producttype</label>
<div class="col-md-4"> 
<label class="radio-inline" for="producttype-0">
<input type="radio" name="producttype" id="producttype-0" value="Male">
Male
</label> 
<label class="radio-inline" for="producttype-1">
<input type="radio" name="producttype" id="producttype-1" value="Female">
Female
</label>
</div>
</div>

<!-- promo_code input-->
<div class="form-group">
<label class="col-md-4 control-label" for="promo_code">promo_code</label>
<div class="col-md-4">
<input id="promo_code" name="promo_code" type="text" placeholder="promo_code" class="form-control input-md">

</div>
</div>

<!-- promo_code input-->
<div class="form-group">
<label class="col-md-4 control-label" for="corfirm">Confirm promo_code</label>
<div class="col-md-4">
<input id="corfirm" name="corfirm" type="text" placeholder="Confirm promo_code" class="form-control input-md">

</div>
</div>

<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for=""></label>
<div class="col-md-4">
<input type="submit" class="btn btn-success" value="sell">
</div>
</div>

</fieldset>
</form>

</body>
</html>

Creating the Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class ProductController extends Controller
{
//
 public function sell(Request $req){
  $Product = new \App\Product;
  $Product->name = $req->name;
  $Product->product_code= $req->product_code;
  $Product->productminmax = $req->productminmax;
  $Product->producttype = $req->producttype;
  $Product->promo_code = $req->promo_code;

  $Product->save();

  echo "Product Created Successfully";

 }
}

Simple Laravel Validation Logic

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class ProductController extends Controller
{
//
 public function sell(Request $req){

  $this->validate($req, [
   'name' => 'required',
   'product_code' => 'required|product_code',
   'productminmax' => 'required|max:10|min:10',
   'producttype' => 'required',
   'promo_code' => 'required|confirmed',
   'promo_code_confirmation' => 'required',
  ]);
  $Product = new \App\Product;
  $Product->name = $req->name;
  $Product->product_code= $req->product_code;
  $Product->productminmax = $req->productminmax;
  $Product->producttype = $req->producttype;
  $Product->promo_code = $req->promo_code;

  $Product->save();

  echo "Product Created Successfully";

 }
}

Displaying All the Errors

@if (count($errors) > 0)
 <div class="alert alert-danger">
 <ul>
  @foreach ($errors->all() as $error)
   <li>{{ $error }}</li>
  @endforeach
 </ul>
 </div>
@endif

Laravel Server side Form Validation- using AJAX Request and Validation

$("#form-id").submit(function(e){
 e.preventDefault();
 $.ajax({
  url: "Your_api_url",
  type: "POST",
  data: new FormData(this),
  contentType: false,
  cache: false,
  processData:false,
  success: function(data){
   //(Good Luck)do something on success
   //append div for success                       
  },
  error: function(data){
   var errors = data.responseJSON;
   for(i in errors){
    $("#div-id").append('<p>'+errors[i]+'</p>');
   }
  }           
 });
});

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.6 Server Side Validation Example Using Resource Controller.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Laravel 5.7 Routing Required Parameter 0

Laravel 5.7 Routing Required Parameter

Today, We want to share with you Laravel 5.7 Routing Required Parameter.In this post we will show you laravel 5.7 routing Required parameters, hear for Routing Required parameters in laravel 5.7 we will give you demo and example for implement.In this post, we will learn about Route Required parameters in laravel 5.7 with an example.

Laravel 5.7 Routing Required Parameter

There are the Following The simple About Laravel 5.7 Routing Required Parameter Full Information With Example and source code.

As I will cover this Post with live Working example to develop route middleware,route parameters controller, so the some route redirect,get route parameters,get route name for this example is following below.

Example 1: Route with Required parameters

There are some more then 3 or more parameters pass which do not remain present within the web custom URL (Uniform Resource Locator), so the PHP or Laravel developers had to use them. Therefor Route parameters get indicated by a encapsulated within {} (curly-braces) with alphabets inside following source code the name of the URL parameter.

Route :: get ('product/{id}', function ($id) {
    echo 'Emp '.$id;
});

Example 2: Laravel (5.7) – Routing to controller with Required parameters

Required Route Parameter

You Can Also More Laravel Routing Examples Full Source Code ForLaravel Route pass multiple Parameters Examples

Routes.php

<?php
 
Route::get('products/{id}', [
    'uses' => '[email protected]',
    'as' => 'company.products',
    'middleware' => ['auth'],
]);
 
Route::post('update/{updateId}', [
    'uses' => '[email protected]',
    'as' => 'update',
]);

ProductController.php

namespace Henri\Http\Controllers;
 
use Auth;
use Henri\Models\Company;
use Henri\Models\Product;
use Illuminate\Http\Request;
 
class ProductController extends Controller{
        public function productCompany(){
                $products = Product::whereUserId(Auth::user()->id)->get();
                return view('company.index')->with('products', $products);
            }
            
            public function getProducts($id){
                $products = Product::where('id', $id)->first();
                if(!$products){
                    if (Auth::check()) {
                        return redirect()->route('company')->with('info', 'We cannot find that product!');
                    }
                }
                return view('company.products')->with('products', $products);   
            }
            
            public function updateProduct(Request $request, $updateId){
                $this->validate($request, [
                    'body' => 'max:255',
                ]);
                
                $products= Product::where('id', $updateId)->first()->update([
                    'body' => $request['body'],
                ]);
                
                return redirect()->back()->with('info', 'Product was updated!');
            }
 
}

Product.blade.php

@include('templates.partials.alerts')
 
@if(Auth::user()->id != $products->user_id)
    View this <a href="news/{{$products->id}}"/>news</a> !
@else
    <form action="{{route('update')}}" method="post">
        {{$products->id}}
    <textarea class="edit" name='body'/>{{$products->body}}</textarea>
    <br/>
    <br/>
    <input type="submit" name="editSubmit" value="Edit Product"/>
    <input type="hidden" name="_token" value="{{csrf_token()}}"/>
    </form>
@endif

Example 3: laravel get request Required parameters

# Required Parameters Template Routes

Route::get('student/{id}', function ($id) {
    return 'Student ID:'.$id;
});

You may define as many Laravel 5.7 route parameters as required by your route:

Route::get('students/{student}/comments/{comment}', function ($studentId, $commentId) {
    //
});

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.7 Routing Required Parameter.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Laravel 5.7 Routing Optional Parameter 0

Laravel 5.7 Routing Optional Parameter

Today, We want to share with you Laravel 5.7 Routing Optional Parameter.In this post we will show you laravel 5.7 routing optional parameters, hear for Route optional parameters in laravel 5.7 we will give you demo and example for implement.In this post, we will learn about Routing optional parameters in laravel 5.7 with an example.

Laravel 5.7 Routing Optional Parameter

There are the Following The simple About Laravel 5.7 Routing Optional Parameter Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 5.7 route wildcard, so the route resource,route middleware for this example is following below.

Example 1: Route with optional parameters

There are some more then 3 or more parameters pass which do not remain present within the web custom URL, so the PHP or Laravel developers had to use them. Therefor Route parameters get indicated by a ? (question mark sign) following source code the name of the URL parameter.

Route :: get ('product/{cat_id?}', function ($cat_id = null) {
    echo $cat_id;
});

Route :: get ('product/{name?}', function ($name = 'Mobile') {
    echo $name;
});

Example 2: Laravel (5.7) – Routing to controller with optional parameters

Optional Route Parameter

You Can Also More Laravel Routing Examples Full Source Code ForLaravel Route pass multiple Parameters Examples

Route::get('product/{name?}', function ($name = 'MyLaravelProject') { return $name;});

Example 3: laravel get request Optional parameters

# Optional Parameters Template Routes

# routes/web.php

Route::get('product/{name?}', function ($name = null) {
    return 'Name: '.$name;
});

Route::get('products/{name?}', function ($name = 'Iphone') {
    return 'Name: '.$name;
});

testing this Laravel routes

# product/{productname} routes:

http://localhost:8080/product
http://localhost:8080/product/hashvel

# products/{productname} routes:

http://localhost:8080/products
http://localhost:8080/products/hashvel

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.7 Routing Optional Parameter.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Simple Laravel Contact Us Form With Email Example 0

Simple Laravel Contact Us Form With Email Example

Today, We want to share with you Simple Laravel Contact Us Form With Email Example.In this post we will show you Create a Laravel Contact Us form with Email, hear for Laravel 5.7 Contact Form With File Attachment Script we will give you demo and example for implement.In this post, we will learn about Laravel 5.7 – Create Bootstrap Contact US Form using Form Request with an example.

Simple Laravel Contact Us Form With Email Example

There are the Following The simple About Simple Laravel Contact Us Form With Email Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Sending Email Messages in Laravel 5.7, so the Submit Contact Form in PHP Laravel 5.7 with toastr notifications jquery for this example is following below.

Setp 1 : Setup laravelcollective

Install Laravel Collective HTML Package with Install Laravel Application

cd myproject
cd myprojectname/public_html
composer require laravelcollective/html

config/app.php

// Laravel Add a Providers with aliases
'providers' => [
....
'Collective\Html\HtmlServiceProvider',
],
'aliases' => [
....
'Form' => 'Collective\Html\FormFacade',
],

Setp 2 : Database Configuration

the .env file >> Add the Laravel file settings credentials

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=example.db.name                                                                                               DB_USERNAME=example.db.username                                                                                           
DB_PASSWORD= example.db.password

Make Laravel Migrations for Feedback Us Table

php artisan make:migration create_feedback_us_table

database/migration/date_ create_feedback_us_table.php

increments('id'); $table->string('name'); $table->string('email'); $table->text('comment'); $table->timestamps(); });
    }

    public function down()
    {
       Schema::drop("feedbackus");
    }
}

Laravel run the following command

php artisan migrate

Setp 3 : Laravel Make The Model

Create a Laravel Model

php artisan make:model Feedback

app/Feedback.php

<?php

namespace App;
use Illuminate\Database\Eloquent\Model;
class Feedback extends Model
{

public $table = 'feedbackus';
public $fillable = ['name','email','comment'];

}

Setp 4 : Define Laravel the Route

routes/web.php

Route::get('feedback-us', '[email protected]');
Route::post('feedback-us', ['as'=>'feedbackus.store','uses'=>'[email protected]']);

Setp 5 : Make a Laravel Controller

app/Http/Controllers/FeedbackController.php

validate($request, [
        'name' => 'required',
        'email' => 'required|email',
        'comment' => 'required'
        ]);

       Feedback::create($request->all());

       return back()->with('success', 'Thanks for feedbacking us!');
   }
}

Setp 6 : Make Laravel the View

resources/views/Feedback.blade.php



<title>Laravel 5.7 Feedback Form Example</title>




<div class="pakainfo container">
<h1>Feedback Form</h1>
<p>Laravel Contact Form With File Attachment Script</p>

@if(Session::has('success'))
   <div class="alert alert-success">
     {{ Session::get('success') }}
   </div>
@endif

{!! Form::open(['route'=>'feedbackus.store']) !!}

<div>has('name') ? 'has-error' : '' }}">
{!! Form::label('Member Name:') !!}
{!! Form::text('name', old('name'), ['class'=>'Feedback form-control', 'placeholder'=>'Enter Member Name']) !!}
<span class="text-danger">{{ $errors->first('name') }}</span>
</div>

<div>has('email') ? 'has-error' : '' }}">
{!! Form::label('Member Email:') !!}
{!! Form::text('email', old('email'), ['class'=>'Feedback form-control', 'placeholder'=>'Enter Member Email']) !!}
<span class="text-danger">{{ $errors->first('email') }}</span>
</div>

<div>has('comment') ? 'has-error' : '' }}">
{!! Form::label('Comment:') !!}
{!! Form::textarea('comment', old('comment'), ['class'=>'Feedback form-control', 'placeholder'=>'Enter Member Comment']) !!}
<span class="text-danger">{{ $errors->first('comment') }}</span>
</div>

<div class="pakainfo form-group">
<button class="gst btn btn-success">Feedback US!</button>
</div>

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

</div>



email.blade.php

You received a comment from : {{ $name }}
<p>
Member Name: {{ $name }}
</p>

<p>
Member Email: {{ $email }}
</p>

<p>
Comment: {{ $user_comment }}
</p>

Laravel Sending the Email

php artisan make:mail 

first of all My account > Login as well as Security > Login to Google

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME= [email protected]
MAIL_PASSWORD= example.generated.app.password
MAIL_ENCRYPTION=tls

FeedbackUsController.php

validate($request, [ 'name' => 'required', 'email' => 'required|email', 'comment' => 'required' ]);
    Feedback::create($request->all()); 

    Mail::send('email',
       array(
           'name' => $request->get('name'),
           'email' => $request->get('email'),
           'user_comment' => $request->get('comment')
       ), function($comment)
   {
       $comment->from('[email protected]');
       $comment->to('[email protected]', 'Admin')->subject('Pakainfo Feedback');
   });

    return back()->with('success', 'Thanks for feedbacking us!'); 
   }
}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Simple Laravel Contact Us Form With Email Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Laravel 5.7 Bootstrap Admin Panel Templates Integrate 0

Laravel 5.7 Bootstrap Admin Panel Templates Integrate

Today, We want to share with you Laravel 5.7 Bootstrap Admin Panel Templates Integrate.In this post we will show you Integrate admin template in Laravel 5.7, hear for Laravel Admin Packages to Use for Backend step by step we will give you demo and example for implement.In this post, we will learn about PHP Laravel 5.7 – Bootstrap Admin Theme Integration example from scratch with an example.

Laravel 5.7 Bootstrap Admin Panel Templates Integrate

There are the Following The simple About Laravel 5.7 Bootstrap Admin Panel Templates Integrate Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.7 Admin Panel Generators, so the Laravel 5.7 Admin Panel Generators for this example is following below.

Laravel Application Directory Structure

There are the following the list of the Simple Application Structure of Laravel 5.7 Framework

Laravel’s App Directory

  • Console
  • Exceptions
  • Http
  • –>Controllers
  • –>Middleware
  • Providers

Laravel’s Bootstrap Directory

  • bootstrap
  • –>cache

Laravel’s Config Directory

  • app.php
  • auth.php
  • broadcasting.php
  • cache.php
  • database.php
  • filesystems.php
  • mail.php
  • queue.php
  • services.php
  • session.php
  • view.php

Database Directory

  • database migrations
  • database seeds

Public Directory

  • images
  • js
  • css

Routes Directory

  • web.php
  • api.php
  • console.php

Storage Directory

Path : storage/app/public

Step 1: Install the Laravel 5.7

composer create-project laravel/laravel adminlaravel_template --prefer-dist

Laravel Define Route

Laravel define the route for the admin template.

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', '[email protected]')->name('home');

Step 2: Create a layout file called default.blade.php

default.blade.php
resources/views/layouts/default.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
@include('includes.head')
</head>
<body>
    <div class="wrapper">
        @include('includes.header')
        @include('includes.sidebar')
        <!-- Contant -->
        <div class="content-wrapper">           
            @yield('content')
        </div>
        <!-- End Content -->
        @include('includes.footer')
    </div>
<!-- Script -->
<script src="{{ URL::asset('js/jquery-1.12.4.min.js') }}" type="text/javascript"></script> <!-- jquery min js -->
<script src="{{ URL::asset('js/bootstrap.min.js') }}" type="text/javascript"></script> <!-- bootstrap js -->
<script src="{{ URL::asset('js/jquery.dataTables.min.js') }}" type="text/javascript"></script> <!-- dataTables js -->
<script src="{{ URL::asset('js/dataTables.responsive.min.js') }}" type="text/javascript"></script> <!-- DataTables Responsive js -->    
<script src="{{ URL::asset('js/responsive.bootstrap4.min.js') }}" type="text/javascript"></script> <!-- Responsive Bootstrap4 js -->
<script src="{{ URL::asset('js/default.js') }}" type="text/javascript"></script> <!-- custom js -->
<script src="{{ URL::asset('js/sidebarmenu.js') }}" type="text/javascript"></script> <!-- custom js -->
<!-- End Script -->
<script>

</script>
@yield ('scripts')    
</body>
</html>

resources/views/includes/head.blade.php

<meta charset="UTF-8">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title>Your_Project_name InfoMedia</title>
<link rel="icon" href="{{ URL::asset('images/favicon.png') }}" type="image/x-icon" /> <!-- Favicon Icon -->

<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,500,600,700" rel="stylesheet"> <!-- Google Font -->

<link href="{{ URL::asset('css/bootstrap.css') }}" rel="stylesheet" type="text/css"/> <!-- Bootstrap -->
<link href="{{ URL::asset('css/responsive.bootstrap.min.css') }}" rel="stylesheet" type="text/css"/> <!-- Responsive Bootstrap  -->
<link href="{{ URL::asset('css/font-awesome.css') }}" rel="stylesheet" type="text/css"/> <!-- Font Awesome -->
<link href="{{ URL::asset('css/style.css') }}" rel="stylesheet" type="text/css"/> <!-- Custom css -->
<link href="{{ URL::asset('css/custom.css') }}" rel="stylesheet" type="text/css"/> <!-- Custom css -->
<link href="{{ URL::asset('css/responsive.css') }}" rel="stylesheet" type="text/css"/> <!-- Custom css -->

resources/views/includes/header.blade.php

<meta charset="UTF-8">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title>Your_Project_name InfoMedia</title>
<link rel="icon" href="{{ URL::asset('images/favicon.png') }}" type="image/x-icon" /> <!-- Favicon Icon -->

<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,500,600,700" rel="stylesheet"> <!-- Google Font -->

<link href="{{ URL::asset('css/bootstrap.css') }}" rel="stylesheet" type="text/css"/> <!-- Bootstrap -->
<link href="{{ URL::asset('css/responsive.bootstrap.min.css') }}" rel="stylesheet" type="text/css"/> <!-- Responsive Bootstrap  -->
<link href="{{ URL::asset('css/font-awesome.css') }}" rel="stylesheet" type="text/css"/> <!-- Font Awesome -->
<link href="{{ URL::asset('css/style.css') }}" rel="stylesheet" type="text/css"/> <!-- Custom css -->
<link href="{{ URL::asset('css/custom.css') }}" rel="stylesheet" type="text/css"/> <!-- Custom css -->
<link href="{{ URL::asset('css/responsive.css') }}" rel="stylesheet" type="text/css"/> <!-- Custom css -->

resources/views/includes/footer.blade.php

<!-- Footer -->
<!--<footer class="footer">
    <h3>Get in Touch with us:</h3>
    <p>For any Suggestion or any types of the help write us to <a href="mailto:[email protected]_Project_name.com"><i class="fa fa-envelope"></i> [email protected]_Project_name.com</a> or Skype : <a href="skype:john.sharma"><i class="fa fa-skype"></i> john.sharma</a></p>
    <p>If you have not gets any message or email from us after purchased this Product, please write us on <a href="mailto:[email protected]_Project_name.com"><i class="fa fa-envelope"></i> [email protected]_Project_name.com</a></p>          
</footer>-->
<!-- End Footer -->

resources/views/includes/sidebar.blade.php

<!-- Sidebar Menu -->
<aside class="main-sidebar">
    <section class="sidebar">
        <ul id="sidebarnav">
                <li {!! currentActivePath('home') !!}><a href="{{ url('home') }}" {!! selectedPath('home') !!}><i class="fa fa-tachometer"></i><span>Dashboard</span></a></li>
                <li {!! currentActivePath('products') !!}><a href="{{ url('products/active') }}" {!! selectedPath('products') !!}><i class="fa fa-ticket"></i><span>Active products</span> <span class="badge badge-pill badge-warning
">1</span></a> </li>
                <li {!! currentActivePath('complete') !!}><a href="{{ url('products/completed') }}" {!! selectedPath('complete') !!}><i class="fa fa-folder"></i><span>Completed products</span> <span class="badge badge-pill badge-warning
">1</span></a> </li>
                    <li {!! currentActivePath('cats') !!}><a href="{{ url('cats') }}" {!! selectedPath('cats') !!}><i class="fa fa-shopping-bag"></i><span>App's</span></a></li>
                    <li {!! currentActivePath('categories') !!}><a href="{{ url('categories') }}" {!! selectedPath('categories') !!}><i class="fa fa-sitemap"></i><span>Categories</span></a></li>
                    <li {!! currentActivePath('usertypes') !!}><a href="{{ url('usertypes') }}" {!! selectedPath('usertypes') !!}><i class="fa fa-sliders"></i><span>usertypes</span></a></li>
                    <li {!! currentActivePath('status') !!}><a href="{{ url('status') }}" {!! selectedPath('status') !!}><i class="fa fa-tasks"></i><span>Status</span></a></li>
                    <li {!! currentActivePath('auto-response') !!}><a href="{{ url('auto-response') }}" {!! selectedPath('auto-response') !!}><i class="fa fa-reply-all"></i><span>Canned response</span></a></li>
                    <li {!! currentActivePath('catinfos') !!}><a href="{{ url('catinfos') }}" {!! selectedPath('catinfos') !!}><i class="fa fa-list-ol"></i><span>cat's info</span></a></li>
                    <li {!! currentActivePath('spam-emails') !!}><a href="{{ url('spam-emails') }}" {!! selectedPath('spam-emails') !!}><i class="fa fa-envelope-open"></i><span>Spam Email's</span></a></li>
        </ul>
    </section>
    <!--<div class="user-icon">
        <a href="user.html" class="user-btn">
            <img src="images/user.svg" alt="">
        </a>
    </div>-->
</aside>
<!-- End Sidebar Menu -->

http/Controllers/HomeController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('home');
    }
}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.7 Bootstrap Admin Panel Templates Integrate.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

PHP Laravel Middleware Route Groups 0

PHP Laravel Middleware Route Groups

Today, We want to share with you PHP Laravel Middleware Route Groups.In this post we will show you laravel route group middleware, hear for Laravel 5.7 Middleware Tutorial With An Example we will give you demo and example for implement.In this post, we will learn about Combined route group with prefix and auth middleware with an example.

PHP Laravel Middleware Route Groups

There are the Following The simple About PHP Laravel Middleware Route Groups Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel auth:api middleware, so the laravel middleware except for this example is following below.

Laravel Middleware group Advantages

There are list of the main advantages of Very useful middleware group in Laravel

  • It simple way to generalize the Laravel Auth source code.
  • We all the save time from reuseble multiple middleware names in multiple places.
  • If You Want to create a middleware in all Laravel 5.7 routes, don’t worry We can just simple add in middleware group.
  • Reduces the complexity.

Setting up middleware group in Laravel

We will display a protected PHP class variable Like as name “$middlewareGroups” which stores simple PHP an empty array

app/Http/Kernel.php

/**
* The Laravel 5.7 application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
	'web' => [
		\App\Http\Middleware\EncryptCookies::class,
		\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
		\Illuminate\Session\Middleware\StartSession::class,
		// \Illuminate\Session\Middleware\AuthenticateSession::class,
		\Illuminate\View\Middleware\ShareErrorsFromSession::class,
		\App\Http\Middleware\VerifyCsrfToken::class,
		\Illuminate\Routing\Middleware\SubstituteBindings::class,
	],
	'api' => [
		'throttle:60,1',
		'bindings',
		'cors'
	],
	'both' => [
		'web',
		'api'
	]
];

Laravel middleware groups

And then, let’s simple code display how we can use these Laravel 5.7 middleware groups in routes/api.php

routes/api.php

Route::group(['middleware' => ['permission', 'api']], function(){
Route::get('product/access_permissions', 'API\Product\[email protected]');
Route::get('product/dashboard', 'API\Product\[email protected]');
Route::get('product/members', 'API\Product\[email protected]');
Route::get('product/member/{member_id}', 'API\Product\[email protected]');
Route::put('product/member/assign_roles/{member_id}', 'API\Product\[email protected]');
});

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Laravel Middleware Route Groups.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Laravel get single value from database 0

Laravel get single value from database

Laravel get single value from database

In this Post We Will Explain About is Laravel get single value from database With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to fetch single row from a table and display data Example

In this post we will show you Best way to implement Eloquent – select single value from database in laravel, hear for php – Fetching and printing a single value from database using laravel with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

How to get single column value from DB

Hello Friends You are most welcome In this post We are going to show you simple steps how to get single value from mysql database using Laravel 5

1])->first(['title']);
 return $live_post->title;
}

Laravel: getting a a single value from a MySQL query

$result = DB::table('users')->select('groupName')->where('username', $username)->first();
return $result->groupName;

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is how to select single field and get a single result with eloquent no id know And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

Polymorphic relationships in Laravel 5.7 Example 0

Polymorphic relationships in Laravel 5.7 Example

Today, We want to share with you Polymorphic relationships in Laravel 5.7 Example.In this post we will show you laravel polymorphic table migration, hear for Laravel Polymorphic Relationship Tutorial we will give you demo and example for implement.In this post, we will learn about laravel query polymorphic relationship with an example.

Polymorphic relationships in Laravel 5.7 Example

There are the Following The simple About Polymorphic relationships in Laravel 5.7 Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel hasmanythrough pivot, so the some laravel eloquent relationships for this example is following below.

Laravel Eloquent Relationships Tutorial with Examples

Laravel Many to Many Polymorphic Relationship Tutorial

class CreatecollageTable extends Migration
{
    public function up()
    {
        Schema::create('collage', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('Collageable_id');
            $table->string('Collageable_type');
            $table->string('name');
            $table->timestamps();
        });
    }
}

With the model relationships defined like so.

class Collage extends Model
{
    public function Collageable()
    {
        return $this->morphTo();
    }
}

class Student extends Model
{
    public function collage()
    {
        return $this->morphMany(Collage::class, 'Collageable');
    }
}

class Teacher extends Model
{
    public function collage()
    {
        return $this->morphMany(Collage::class, 'Collageable');
    }
}

Good Luck! That’s all that is needed for this Laravel 5.7 relation. Making use of it is no different from defining a standard Simple Polymorphic one-to-many relationship.

// assign a Collage to a Student
$Student->collage()->create(['name' => 'Increase conversion rate']);

// get all collage associated with an Teacher
$collage = $Teacher->collage;

Simple Laravel 5.7 Polymorphic relationships Examples

class CreateleavesTable extends Migration
{
    public function up()
    {
        Schema::create('leaves', function (Blueprint $table) {
            $table->unsignedInteger('Collage_id');
            $table->foreign('Collage_id')->references('id')->on('collage');
            $table->unsignedInteger('Leaveable_id');
            $table->string('Leaveable_type');
            $table->string('value');
            $table->enum('type', ['target', 'start', 'running', 'end']);
            $table->timestamps();
        });
    }
}
[/php

<p>With the Laravel 5.7 model relationships defined like so.</p>
[php]
class Leave extends Model
{
    protected $guarded = [];

    public function Leaveable()
    {
        return $this->morphTo();
    }
}

class Collage extends Model
{
    public function customDatas()
    {
        return $this->morphedByMany(Student::class, 'Leaveable', 'leaves')
            ->withTimestamps()
            ->withPivot(['value', 'type']);
    }

    public function customDatas()
    {
        return $this->morphedByMany(customData::class, 'Leaveable', 'leaves')
            ->withTimestamps()
            ->withPivot(['value', 'type']);
    }
}

class Student extends Model
{
    public function leaves()
    {
        return $this->morphToMany(Collage::class, 'Leaveable');
    }
}

class customData extends Model
{
    public function leaves()
    {
        return $this->morphToMany(Collage::class, 'Leaveable');
    }
}

Interacting with these Laravel 5.7 relationships is still extremely simple

// get all collage for a customData
$leaves = $customData->leaves;

// output all Leave values for all collage
@foreach($leaves as $Leave)
      {{ $Leave->pivot->value }}
@endforeach

// store an Leave for a Student
$Collage = $Student->collage()->create(
    ['name' => 'Increase conversion your rate'
]);

$Collage->leaves()->attach($Student, [
    'type' => 'target', 
    'value' => '9898'
]);

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Polymorphic relationships in Laravel 5.7 Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Laravel Nested Relationships in Eloquent Example 0

Laravel Nested Relationships in Eloquent Example

Today, We want to share with you Laravel Nested Relationships in Eloquent Example.In this post we will show you Laravel Deeply nested relationships, hear for Get a nested relationship in Laravel we will give you demo and example for implement.In this post, we will learn about Eloquent nested relations with where clause with an example.

Laravel Nested Relationships in Eloquent Example

There are the Following The simple About Laravel Nested Relationships in Eloquent Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Retrieving nested relationships using Laravel, so the Nested relationships when parent is a many-to-many relationship for this example is following below.

Laravel Eloquent Relationships Tutorial Example From Scratch

This is the Laravel Simple SQL Relationships query that works!

SELECT member.id, 
       member.firstname, 
       member.lastname, 
       team_scores.score 
FROM   teams 
       JOIN countries 
         ON countries.id = teams.country_id 
       JOIN vanues 
         ON countries.id = vanues.country_id 
       JOIN member 
         ON vanues.id = member.vanue_id 
       JOIN team_scores 
         ON team_scores.member_id = member.id 
WHERE  team_scores.team_id = 1 
GROUP  BY member.id 

These are my Eloquent relations

Team Model

class Team extends Eloquent
{
    protected $table = 'teams';

    public function country()
    {
        return $this->belongsTo('Country');
    }
}

Country Model

class Country extends Eloquent
{
    protected $table = 'countries';

    public function vanues()
    {
        return $this->hasMany('Vanue');
    }

    public function team()
    {
        return $this->hasMany('Team');
    }
}

Vanue Model

class Vanue extends Eloquent {

    protected $table = 'vanues';

    public function member()
    {
        return $this->hasMany('Member');
    }

    public function country()
    {
        return $this->belongsTo('Country');
    }
}

Member Model

class Member extends Eloquent
{
    protected $table = 'member';

    public function vanue()
    {
        return $this->belongsTo('Vanue');
    }

    public function teamscore()
    {
        return $this->belongsToMany('Team', 'team_scores', 'member_id', 'team_id')
            ->withPivot('score')
            ->withTimestamps();
    }
}

PHP Laravel nested relationships Get Data

return Team::with('country.vanues.member')->get();

If you only want to select simple all the fields from the member table, use this:

return Team::with(['country.vanues.member' => function ($query) {
    $query->select('id', '...');
}])->get();

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Nested Relationships in Eloquent Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.