Laravel 5 Pagination: Multiple Paginations in the same Page

In this note I write down my experience regarding multiple paginationin the same page using Laravel 5:

In your laravel controller:


//  Program Degree
$object1s = Object1::orderBy('name', 'desc')
                    ->paginate(2, ['*'], 'page_1s');

// Master Program
$object2s = Object2::orderBy('name', 'desc')
                    ->paginate(2, ['*'], 'page_2s');

// Online Course
$object3s = Object3::orderBy('name', 'desc')
                    ->paginate(2, ['*'], 'page_3s');

In your laravel view:

  // Nothing to change in the view

Now you will have following paginated urls in your application:

  1. http://localhost:8000/yourpage?page_1s=2
  2. http://localhost:8000/yourpage?page_2s=2
  3. http://localhost:8000/yourpage?page_3s=2
  4. for special purpose you can custom url to handle all paginations in same time become:
    1. http://localhost:8000/yourpage?page_1s=2&page_2s=3&page_3s=4

Using Switch Case on Laravel 5 Blade

In this post I will show you about how to add Switch Case to Laravel 5.x blade template engine.

Source: Link

On app/Providers/AppServiceProvider.php do following steps:

use Illuminate\Support\Facades\Blade;

On function function boot() add following line:

// Switch case directive
Blade::extend(function($value, $compiler){
    $value = preg_replace('/(\s*)@switch\((.*)\)(?=\s)/', '$1<?php switch($2):', $value);     $value = preg_replace('/(\s*)@endswitch(?=\s)/', '$1endswitch; ?>', $value);
    $value = preg_replace('/(\s*)@case\((.*)\)(?=\s)/', '$1case $2: ?>', $value);
    $value = preg_replace('/(?<=\s)@default(?=\s)/', 'default: ?>', $value);
    $value = preg_replace('/(?<=\s)@breakswitch(?=\s)/', '<?php break;', $value);
    return $value;
});

And now you can use following blade notation to make switch case condition.

@switch($k)
    @case(0)
        fsdfsdf
        @breakswitch
    @case(1)
      sdfsdf
        @breakswitch
    @case(2)
        sdf
        @breakswitch
@endswitch

Set up – Install Laravel5 on Ubuntu

  1. composer create-project laravel/laravel BelajarTest –prefer-dist
  2. cd BelajarTest
  3. test runs several command
    1. ./artisan (if not work do this :  $sudo chmod +x ./artisan )
    2. ./vendor/phpunit (if not work do this :  $sudo chmod +x./vendor/phpunit )
  4. now run ./artisan serve
  5. open browser and open localhost:8000
  6. if you get “Segmentation fault (core dumped)” please open this link

Laravel server error Segmentation fault (core dumped)

Pelatihan Pemrograman Java Web dengan Spring Boot Gratis klik disini.

Pelatihan Pemrograman Web dengan Java secara gratis dibimbing oleh trainers yang berpengalaman dibidang pengembangan applikasi berbasis Java enterprise.

Peserta per batch dibatasi hanya 15 orang.

WhatsApp Image 2020-03-10 at 08.55.54

Daftar Java web Bootcamp Gratis disini https://www.beanary.tech/ 

 

 

 

I just learned Laravel 5 on my Ubuntu 14.04 laptop, and I got this error message “Segmentation fault (core dumped)” after I ran and open 127.0.0.1:8000 / localhost:8000 in browser. to solve this error “Segmentation fault (core dumped)” just do following steps:

  1. rm ./vendor/compiled.php
  2. composer update
  3. re-run server by executing ./artisan server
  4. go to browser open 127.0.0.1:8000/localhost:8000, now everything just work correcly.

LaravelServerErrorLaravelServerError2LaravelServerError3LaravelServerErrorSolved

ok, that are how to solve error “Segmentation fault (core dumped)” in laravel 5

Or:

composer dump-autoload

composer update

./artisan cache:clear

Laravel 4 return wrong id after join table

To solve this we could add a select clause to only select the specific columns:

$exams = Exam::select(‘exams.*’)->where(function($query){
$user = Sentry::getUser();
if (!$user->hasAnyAccess([‘admin’])) {
$query->where(‘user_id’, ‘=’, $user->id);
}
})->join(‘exams_questions’,function($join) use ($question_id) {
$join->on(‘exams_questions.exam_id’, ‘=’, ‘exams.id’)
->where(‘exams_questions.question_id’, ‘=’, $question_id);
})->with(array(‘user’, ‘exam_questions’))->paginate(10);