Topic: Laravel

Laravel 6 – Simple Pagination Example Tutorial 0

Laravel 6 - Simple Pagination Example Tutorial

Today, We want to share with you Laravel 6 – Simple Pagination Example Tutorial.In this post we will show you Laravel 6 Pagination With Bootstrap Tables Example, hear for laravel 6 pagination parameters we will give you demo and example for implement.In this post, we will learn about Laravel 6 pagination example from scratch with an example.

Laravel 6 – Simple Pagination Example Tutorial

There are the Following The simple About Laravel 6 Simple Pagination with Database Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Simple pagination in PHP with the Laravel 6 pagination package, so the some major files and Directory structures for this example is following below.

Step 1: Add Route

routes/web.php

Route::get('products', '[email protected]');

Step 2: Create Laravel 6 Controller

app/Http/Controllers/ProductController.php

<?php
   
namespace App\Http\Controllers;
   
use Illuminate\Http\Request;
use App\Product;
  
class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data = Product::paginate(10);
        return view('products',compact('data'));
    }
}

Step 3: Create Laravel Blade File

resources/views/products.blade.php

@extends($theme)
  
@section('content')
  
<table class="table table-bordered">
    <thead>
        <tr>
            <th>Name</th>
            <th width="300px;">Action</th>
        </tr>
    </thead>
    <tbody>
        @if(!empty($data) && $data->count())
            @foreach($data as $key => $value)
                <tr>
                    <td>{{ $value->name }}</td>
                    <td>
                        <button class="btn btn-danger">Delete</button>
                    </td>
                </tr>
            @endforeach
        @else
            <tr>
                <td colspan="10">There are no data.</td>
            </tr>
        @endif
    </tbody>
</table>
   
{!! $data->links() !!}
  
@endsection

If We need advance Level used of simple Laravel 6 pagination then We can see bellow how to use.

Pagination with appends Data/parameter

{!! $data->appends(['sort' => 'votes'])->links() !!}

Laravel Pagination with some appends request all more parameters

{!! $data->appends(Request::all())->links() !!}

Laravel 6 Tags :

pagination in laravel 6, laravel 6 pagination example blade, laravel 6 pagination example code, laravel 6 pagination example, create pagination in laravel 6 example, pagination link laravel 6

We can also step by step see in more advance Level Information from here: Laravel 6 Pagination From Scratch.

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about Laravel 6 – Simple Pagination Example Tutorial.
I would like to have feedback on my infinityknow.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 Object Oriented Programming Tutorial Example 0

PHP Object Oriented Programming Tutorial Example Step By Step From Scratch

Today, We want to share with you PHP Object Oriented Programming Tutorial Example Step By Step From Scratch.In this post we will show you wordpress plugin require another plugin, hear for PHP Classes & Objects – Introduction to OOP PHP we will give you demo and example for implement.In this post, we will learn about object-oriented php: concepts, techniques, and code pdf with an example.

PHP Object Oriented Programming Tutorial Example Step By Step From Scratch

There are the Following The simple About PHP Object Oriented Programming Tutorial Example Step By Step From Scratch Full Information With Example and source code.

As I will cover this Post with live Working example to develop Learn Object Oriented Programming (OOP) in PHP
, so the PHP Object Oriented Programming Tutorial for Beginners is used for this example is following below.

PHP Provided OOPS programming PHP Object Oriented Programming Quick Reference Guide which bundles data (properties) and related functions or methods in independent units stands for objects.

Step 1: Creating a Class

Description/examples

<?php
class TamilrockersClass {
   // defining a behavior
   public $myProperty = 'a behavior value';

   // defining a method
   public function display() {
     echo $this->myProperty;
   }
}

$custom_varible = new TamilrockersClass();
$custom_varible->display();
?>
  

Output:

a behavior value

Step 2: Visibility (public, protected, private)

Description/examples

<?php
class TamilrockersClass {
  public $custom_varible1 = 'public custom_varible';
  protected $custom_varible2 = 'protected custom_varible';
  private $custom_varible3 = 'private custom_varible';

  function printHello() {
    echo $this->custom_varible1 . '<br>';
    echo $this->custom_varible2 . '<br>';
    echo $this->custom_varible3 . '<br>';
  }
}

$obj = new TamilrockersClass();
echo $obj->custom_varible1 . '<br>'; // prints public custom_varible
$obj->printHello(); // prints all

// if uncommented followings will produce fatal errors
/*
* echo $obj->custom_varible2; // Fatal Error
* echo $obj->custom_varible3; // Fatal Error
*/

Output:

public custom_varible
public custom_varible
protected custom_varible
private custom_varible

Step 3: Class constants(Scope Resolution Operator (::), Using ‘self’)

Description/examples

<?php
class TamilrockersClass {
   const PI = 3.14159;

  function showPI() {
       echo self::PI . "<br>";
  }
}

echo TamilrockersClass::PI . "<br>";
$class = new TamilrockersClass();
$class->showPI();
echo $class::PI . "<br>";
?>

Output:

3.14159
3.14159
3.14159

Step 4: static properties and methods(class constants, static keyword)

Description/examples

<?php
class TamilrockersClass {
  static $custom_varible = 'a static behavior';

  static function firstMthd() {
    return self::$custom_varible;
  }
}

echo TamilrockersClass::$custom_varible . '<br>';
echo TamilrockersClass::firstMthd();
?>

Output:

a static behavior
a static behavior

Step 5: Constructors and destructors

Description/examples

 <?php
class TamilrockersClass {
   private $prop;

   function __construct($custom_varible) {
     echo 'In constructor of ' . __CLASS__ . '<br>';
     $this->prop = $custom_varible;
   }

   public function displayProp() {
     echo $this->prop .'<br>';
   }

   function __destruct() {
     echo 'destroying ' . __CLASS__;
   }
}

$a = new TamilrockersClass('the behavior value');
$a->displayProp();
?>

Output:

In constructor of TamilrockersClass
the behavior value
destroying TamilrockersClass

Step 6: Inheritance:

Description/examples

<?php
class MyParentClass {
  protected $custom_varible = 'a super call behavior';

  public function display() {
     echo $this->custom_varible . '<br>';
  }
}
class MySubclass extends MyParentClass {
  public function getVar() {
     return 'returning ' . $this->custom_varible;
  }
}

$a = new MySubClass();
$a->display();
echo $a->getVar();
?>

Output:

a super call behavior
returning a super call behavior

Step 7: Inheritance and Construct/destruct

Description/examples

<?php
class A {
   protected static $x = 'value x';
   function __construct() {
     echo 'In constructor of ' . __CLASS__ . '<br>';
   }
}
class B extends A {
   function __construct() {
     parent::__construct();
     echo parent::$x .'<br>';
     echo 'In constructor of ' . __CLASS__ . '<br>';
   }
}

$b = new B();

Output:

In constructor of A
value x
In constructor of B

Step 8: Method overriding

Description/examples

<?php
class A {
  function firstMthd() {
    return "firstMthd from A";
  }
}

class B extends A {
  function firstMthd() {
       return "firstMthd from B, ".
       parent::firstMthd();
  }
}

$a = new A;
echo($a->firstMthd());
echo('<br>');
$b = new B;
echo($b->firstMthd());
?>

Output:

firstMthd from A
firstMthd from B, firstMthd from A

Step 9: Abstract classes

Description/examples

<?php
abstract class A{
  abstract protected function firstMthd();

  public function doSomething(){
    $this->firstMthd();
  }
}
class B extends A{
  protected function firstMthd(){
    echo 'firstMthd called';
  }
}

$b = new B();
$b->doSomething();

Output:

firstMthd called

Step 10: Interfaces

Description/examples

<?php
interface Work {
  public function runWork();
  public function secondMthd();
}

abstract class WorkImpl implements Work {
  public function runWork() {
    echo $this->secondMthd();
  }
}

class WorkImpl2 extends WorkImpl {
  public function secondMthd() {
    return "another method running task ";
  }
}

$task = new WorkImpl2();
$task->runWork();
?>

Output:

another method running task

Step 11: Traits

Description/examples

<?phpbehavior
trait  FirstTrait{
  private $custom_varible;

  function __construct($str) {
   $this->custom_varible = $str;
  }

  public function aTraitFunction() {
   echo __METHOD__ . ", from FirstTrait:  $this->custom_varible<br>";
  }

  public function aTraitFunction2() {
   echo __METHOD__ . ", from FirstTrait:  $this->custom_varible<br>";
  }

  function __toString() {
   return __CLASS__ . ", custom_varible=$this->custom_varible <br>";
  }
}

trait SecondTrait{
  public function aTraitFunction2() {
   echo __METHOD__ . ", from SecondTrait:  $this->custom_varible<br>";
  }
}

class BClass {
  public function aTraitFunction2() {
   echo __METHOD__ . ", from BClass:  $this->custom_varible<br>";
  }
}

class MainClass extends BClass {
  use FirstTrait, SecondTrait{
   SecondTrait::aTraitFunction2 insteadof FirstTrait;
  }

  public function aTraitFunction() {
   echo __METHOD__ . ", frome MainClass: $this->custom_varible<br>";
  }
}

$a = new MainClass('a string');
echo $a;
$a->aTraitFunction();
$a->aTraitFunction2();

Output:

MainClass, custom_varible=a string
MainClass::aTraitFunction, frome MainClass: a string
SecondTrait::aTraitFunction2, from SecondTrait: a string

Step 12: Final keyword

Description/examples

class A {
  final function display() {
   echo "displaying in " . __CLASS__;
  }
}
class B extends A {
  function display() {
   echo "displaying in " . __CLASS__;
  }
}

$b = new B();
$b->display();

Output:

Fatal error: Cannot override final method A::display() in D:\eclipse-workspace\php-oop\final.php on line 13

Example 2

final class A {
}
class B extends A {
}

$b = new B();

Output:

Fatal error: Class B may not inherit from final class (A) in D:\eclipse-workspace\php-oop\final-class.php on line 5

Step 13: Objects equality

Description/examples

<?php
class TamilrockersClass {
}

function toString($bool) {
  if ($bool === false) {
   return 'FALSE';
  } else {
   return 'TRUE';
  }
}

$a = new TamilrockersClass();
$b = new TamilrockersClass();
$c = $a;

echo '<br>$a==$b : ' . toString($a == $b);
echo '<br>$a===$b : ' . toString($a === $b);
echo '<br>$a==$c : ' . toString($a == $c);
echo '<br>$a===$c : ' . toString($a === $c);
  

Output:

$a==$b : TRUE
$a===$b : FALSE
$a==$c : TRUE
$a===$c : TRUE

Step 14: Object iteration

Description/examples

<?php
class MovieClass {
  public $str = 'a str behavior';
  public $int = 3;
  protected $str2 = "a protected str behavior";
  private $str3 = "a private str behavior";

  function display(){
    foreach($this as $key => $value){
      echo "$key => $value <br>";
    }
  }
}

$a = new MovieClass();
$a->display();
echo '----<br>';
foreach($a as $key => $value){
	echo "$key => $value <br>";
}

Output:

str => a str behavior
int => 3
str2 => a protected str behavior
str3 => a private str behavior
----
str => a str behavior
int => 3

Step 15: Auto-loading Classes

Description/examples

<?php
spl_autoload_register(function ($className) {
 	echo "including $className.php <br>";
	 include $className . '.php';
});

$a = new A();
$b = new B();

Output:

including A.php
including B.php

Step 16: String representation of objects

Description/examples

<?php
class TamilrockersClass{

  private $custom_varible = 'a behavior';

  public function __toString(){
    return "TamilrockersClass: custom_varible = '$this->custom_varible'";
  }
}

$a = new TamilrockersClass();
echo $a;

Output:

TamilrockersClass: custom_varible = 'a behavior'

Step 17: Property Overloading

Description/examples

<?php
class TamilrockersClass {
  private $arr;

  public function __set($name, $value) {
   $this->arr[$name] = $value;
  }

  public function __get($key) {
   if (array_key_exists($key, $this->arr)) {
    return $this->arr[$key];
   }
   return null;
  }

  public function __isset($name) {
   if (isset($this->arr[$name])) {
    echo "Property $name is set.<br>";
   } else {
    echo "Property $name is not set.<br>";
   }
  }

  public function __unset($name) {
   unset($this->arr[$name]);
   echo "$name is unset <br>";
  }
}
$tamilObj = new TamilrockersClass();
$tamilObj->name="joe";// will trigger __set
var_dump($tamilObj);
echo '<br>';
echo $tamilObj->name; //will trigger __get
echo '<br>';
isset($tamilObj->name);//will trigger __isset
unset($tamilObj->name);//will trigger __unset
var_dump($tamilObj);
?>

Output:

object(TamilrockersClass)#1 (1) { ["arr":"TamilrockersClass":private]=> array(1) { ["name"]=> string(3) "joe" } }
joe
Property name is set.
name is unset
object(TamilrockersClass)#1 (1) { ["arr":"TamilrockersClass":private]=> array(0) { } }

Step 18: Method overloading(__call(), __callStatic)

Description/examples

<?php
class TamilrockersClass {

  public function __call($name, $paramArr) {
    // do something based on method name and params
    return "<br>returning result of method: $name , params: "
      . print_r($paramArr, true) . "<br>";
	}

	public static function __callStatic($name, $paramArr) {
    // do something based on method name and params
    return "<br>returning result of static method: $name , params: "
      . print_r($paramArr, true) . "<br>";
	}
}
$a = new TamilrockersClass();
echo $a->someMethod("some arg");
echo TamilrockersClass::someStaticMethod("some arg for static method");
?>

Output:

returning result of method: someMethod , params: Array ( [0] => some arg )

returning result of static method: someStaticMethod , params: Array ( [0] => some arg for static method )

Step 19: Calling object as a function

Description/examples

<?php
class TamilrockersClass {

  public function __invoke() {
   //do something on being invoked as a function
    echo "invoked triggered<br>";
  }
}

function myFunction(Callable $func) {
  $func();
  return "returning from myFunction";
}

$a = new TamilrockersClass();
//$a() this also works
echo myFunction($a);

Output:

invoked triggered
returning from myFunction

Step 20: Object Cloning

Description/examples

<?php
class TamilrockersClass {
  public $custom_varible;

  public function __construct() {
   $this->custom_varible = new MyOtherClass();
  }

  public function __clone() {
   $this->custom_varible = clone $this->custom_varible;
  }
}
class MyOtherClass {
  private $str = 'some string';

  function getStr() {
    return $this->str;
  }
}

function toString($bool) {
  if ($bool === false) {
   return 'FALSE';
  } else {
   return 'TRUE';
  }
}
$a = new TamilrockersClass();
$b = clone $a;
//using identity operator === to see two '$custom_varible' have the same references
echo 'are internal objects equal: ' . toString($a->custom_varible === $b->custom_varible);

Output:

are internal objects equal: FALSE

Step 21: Serialization

Description/examples

<?php
class TamilrockersClass {
  public $date;
  public $str;
  function __sleep() {
    return array('date');
  }

  function __wakeup() {
    echo "wakeup triggered <br>";
  }
}

date_default_timezone_set("America/Chicago");
$a = new TamilrockersClass();
$a->date = date("y/m/d");
$s = serialize($a);

echo "serialized: <br>";
echo $s;
echo "<br>";

echo "unserializing<br>";
$b = unserialize($s);
echo 'unserialized object:';
echo var_dump($b);
echo "<br>";
echo 'unserialized date: ' . $b->date;

Output:

serialized:
O:7:"TamilrockersClass":1:{s:4:"date";s:8:"16/10/25";}
unserializing
wakeup triggered
unserialized object:object(TamilrockersClass)#2 (2) { ["date"]=> string(8) "16/10/25" ["str"]=> NULL }
unserialized date: 16/10/25

Step 22: Exporting custom_varibleiables

Description/examples

<?php
class MovieClass {
  public $custom_varible = 4;

  public static function __set_state($arr) {
    $a = new MovieClass();
    $a->custom_varible = $arr['custom_varible'];
    return $a;
 }
}

$a = new MovieClass();
$v = custom_varible_export($a, true);
echo "exported custom_varibleiable:<br> $v <br>";
echo "<br>importing custom_varibleiable:<br>";
eval('$e=' . $v . ';');
var_dump($e);

Output:

exported custom_varibleiable:
MovieClass::__set_state(array( 'custom_varible' => 4, ))

importing custom_varibleiable:
object(MovieClass)#2 (1) { ["custom_varible"]=> int(4) }

Step 23: Controlling debug info

Description/examples

class MovieClass {
	 private $custom_varible = 10;
	 private $str = 'a string';

	 public function __debugInfo() {
		  return ['string' => $this->str];
	}
}

$a = new MovieClass();
var_dump($a);

Output:

object(MovieClass)#1 (1) { ["string"]=> string(8) "a string" }

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about PHP Object Oriented Programming Tutorial Example Step By Step From Scratch.
I would like to have feedback on my infinityknow.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 PHP Convert Object To An Array Examples 0

Today, We want to share with you Simple PHP Convert Object To An Array Examples.In this post we will show you wordpress plugin require another plugin, hear for convert array of objects to array php we will give you demo and example for implement.In this post, we will learn about PHP : Convert or Cast Array to Object & Object to Array with an example.

Simple PHP Convert Object To An Array Examples

There are the Following The simple About Simple PHP Convert Object To An Array Examples Full Information With Example and source code.

As I will cover this Post with live Working example to develop PHP – Convert Array to Object with stdClass, so the php convert multidimensional object to array is used for this example is following below.

Example 1: Convert an object to associative array in PHP

<?php
    /*** simple PHP create an object ***/
    $obj = new stdClass;
    $obj->movie = 'movie';
    $obj->song = 'song';
    $obj->tamilrokers = 'tamilrokers';

    /*** PHP cast the object ***/
    $array = (array) $obj;

    /*** Display the results ***/
    print_r( $array );
?>

Output

Array
(
    [movie] => movie
    [song] => song
    [tamilrokers] => tamilrokers
)

Example 2: Convert a PHP object to an associative array

<?php
    /*** a slightly more complex array ***/
    $obj = new stdClass;
    $obj->movie = 'movie';
    $obj->song = new stdClass;
    $obj->song->tamilrokers = 'tamilrokers';

    /*** PHP cast the object to array ***/
    $array = (array) $obj;

    /*** Display the results ***/
    print_r( $array );
?>

Output

Array
(
    [movie] => movie
    [song] => stdClass Object
	(
	    [tamilrokers] => tamilrokers
	)
)

Example 3 : Convert object to an array in PHP

<?php
    /***PHP a complex object ***/
    $obj = new stdClass;
    $obj->movie = new stdClass;
    $obj->movie->tamilrokers = 'tamilrokers';
    $obj->song = 'song';

    /**
    *
    * Convert an object to an array
    *
    * @param    object  $object The object to convert in PHP
    * @reeturn      array
    *
    */
    function objectToArray( $object )
    {
        if( !is_object( $object ) && !is_array( $object ) )
        {
            return $object;
        }
        if( is_object( $object ) )
        {
            $object = get_object_vars( $object );
        }
        return array_map( 'objectToArray', $object );
    }

    /*** PHP convert the array to object ***/
    $array = objectToArray( $obj );

    /*** Display the array ***/
    print_r( $array );
?>

Output

Array
(
    [movie] => Array
        (
            [tamilrokers] => tamilrokers
        )

    [song] => song
)

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about Simple PHP Convert Object To An Array Examples.
I would like to have feedback on my infinityknow.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.

check if folder exists before create directory Laravel 0

check if folder exists before create directory Laravel

Today, We want to share with you check if folder exists before create directory Laravel.In this post we will show you check folder exist laravel, hear for laravel check if directory exists we will give you demo and example for implement.In this post, we will learn about laravel storage check if directory exists with an example.

check if folder exists before create directory

There are the Following The simple About PHP check if folder exists before create directory Full Information With Example and source code.

As I will cover this Post with live Working example to develop check if folder exists laravel, so the create new directory in laravel for this example is following below.

Laravel Controller Method:

public function saveProducts(Request $request)
{
    $dir_path = public_path('upload/pakainfo.com');
   
    if(!File::isDirectory($dir_path)){
        File::makeDirectory($dir_path, 0777, true, true);
    }
   
    dd('Working Fine ___ done');
}

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about folder exists or not in laravel.
I would like to have feedback on my infinityknow.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 checking if record exists 0

laravel checking if record exists

Today, We want to share with you laravel checking if record exists.In this post we will show you check if row exists laravel, hear for How to check if record exists or not in Laravel 5? we will give you demo and example for implement.In this post, we will learn about laravel validation check if exists in database with an example.

laravel checking if record exists

There are the Following The simple About laravel checking if record exists Full Information With Example and source code.

As I will cover this Post with live Working example to develop check object null in laravel, so the some check if record exists in laravel for this example is following below.

$product = Products::where('status', ‘=’, Input::get('status'))->first();
if ($product === null) {
// product doesn’t exist
}

And if you only want to check

if (Products::where('status', ‘=’, Input::get('status'))->count() > 0) {
// product found
}

Or even nicer

if (Products::where('status', ‘=’, Input::get('status'))->exists()) {
// product found
}

How to check if record exists or not in Laravel 5?

$product = Product::where('pcode',Input::get('pcode'))->first();
if (is_null($product)) {
   print_r("pcode is exists");
}

   print_r("pcode is not exists");

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about checking if record exists.
I would like to have feedback on my infinityknow.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.