Should Return to the Page Even Without Login in Laravel 5.4

I am working on laravel 5.4 project. I want to access some pages even without logged in but it always redirect to the login page. Here's my code. Is there anything i can do in middleware? Can you guys help me with this? i'm not really good in laravel. Thank you in advance guys.

I am working on laravel 5.4 project. I want to access some pages even without logged in but it always redirect to the login page. Here's my code. Is there anything i can do in middleware? Can you guys help me with this? i'm not really good in laravel. Thank you in advance guys.

Route

<?php

Route::get('/', function () {
return view('pages.index');
});

Auth::routes();

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

Route::get('/modal_add_course_category', '[email protected]_add_course_category');
Route::post('/save_category', '[email protected]_category');

//header routes
Route::get('/ak_news', '[email protected]_news');

Controller

public function ak_news()
{
$newscategory = DB::table('tak_news_category')->get();

$news = DB::table('tak_news')
    -&gt;select('tak_news.*', 'tak_news.id as newsid', 'tak_news_category.id', 'tak_news_category.tak_news_category')
    -&gt;join('tak_news_category', 'tak_news_category.id', '=', 'tak_news.tak_category_id')
    -&gt;whereRaw('MOD(tak_news.id, 2) = 0')
    -&gt;get();

$news1 = DB::table('tak_news')
    -&gt;select('tak_news.*', 'tak_news.id as newsid', 'tak_news_category.id', 'tak_news_category.tak_news_category')
    -&gt;join('tak_news_category', 'tak_news_category.id', '=', 'tak_news.tak_category_id')
    -&gt;inRandomOrder()-&gt;limit(1)
    -&gt;whereRaw('MOD(tak_news.id, 1) = 0')
    -&gt;get();
$news2 = DB::table('tak_news')
    -&gt;select('tak_news.*', 'tak_news.id as newsid', 'tak_news_category.id', 'tak_news_category.tak_news_category')
    -&gt;join('tak_news_category', 'tak_news_category.id', '=', 'tak_news.tak_category_id')
    -&gt;inRandomOrder()-&gt;limit(1)
    -&gt;get();

$latestnews = DB::table('tak_news')
    -&gt;select('tak_news.*', 'tak_news.id as newsid', 'tak_news_category.id', 'tak_news_category.tak_news_category')
    -&gt;join('tak_news_category', 'tak_news_category.id', '=', 'tak_news.tak_category_id')
    -&gt;orderBY('tak_news.id', 'DESC')
    -&gt;limit(4)
    -&gt;get();

$editors = DB::table('tak_news')
    -&gt;select('tak_news.*', 'tak_news.id as newsid', 'tak_news_category.id', 'tak_news_category.tak_news_category')
    -&gt;join('tak_news_category', 'tak_news_category.id', '=', 'tak_news.tak_category_id')
    -&gt;where('tak_news.id', '=', '6')
    -&gt;get();

return view('pages.news_page', compact('newscategory', 'news', 'news1', 'news2', 'latestnews', 'editors'));

}

View layout

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
<!-- Mobile Specific Meta -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Favicon-->
<link rel="shortcut icon" href="img/fav.png">
<!-- Author Meta -->
<meta name="author" content="colorlib">
<!-- Meta Description -->
<meta name="description" content="">
<!-- Meta Keyword -->
<meta name="keywords" content="">
<!-- meta character set -->
<meta charset="UTF-8">
<!-- Site Title -->
<title>yeah</title>
<link href="https://fonts.googleapis.com/css?family=Poppins:100,200,400,300,500,600,700" rel="stylesheet">
<!--
CSS
============================================= -->
<link rel="stylesheet" href="css/linearicons.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/magnific-popup.css">
<link rel="stylesheet" href="css/nice-select.css">
<link rel="stylesheet" href="css/animate.min.css">
<link rel="stylesheet" href="css/owl.carousel.css">
<link rel="stylesheet" href="css/jquery-ui.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<header>

    &lt;div class="container main-menu" id="main-menu"&gt;
        &lt;div class="row align-items-center justify-content-between"&gt;
            &lt;nav id="nav-menu-container"&gt;
                &lt;ul class="nav-menu"&gt;
                    &lt;li class="menu-active"&gt;&lt;a href="index.html"&gt;Home&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="archive.html"&gt;Archive&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="category.html"&gt;Category&lt;/a&gt;&lt;/li&gt;
                    &lt;li class="menu-has-children"&gt;&lt;a href=""&gt;Post Types&lt;/a&gt;
                    &lt;ul&gt;
                        &lt;li&gt;&lt;a href="standard-post.html"&gt;Standard Post&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href="image-post.html"&gt;Image Post&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href="gallery-post.html"&gt;Gallery Post&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href="video-post.html"&gt;Video Post&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href="audio-post.html"&gt;Audio Post&lt;/a&gt;&lt;/li&gt;
                    &lt;/ul&gt;
                &lt;/li&gt;
                &lt;li&gt;&lt;a href="about.html"&gt;About&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href="contact.html"&gt;Contact&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;/nav&gt;&lt;!-- #nav-menu-container --&gt;
            &lt;div class="navbar-right"&gt;
                &lt;form class="Search"&gt;
                    &lt;input type="text" class="form-control Search-box" name="Search-box" id="Search-box" placeholder="Search"&gt;
                    &lt;label for="Search-box" class="Search-box-label"&gt;
                        &lt;span class="lnr lnr-magnifier"&gt;&lt;/span&gt;
                    &lt;/label&gt;
                    &lt;span class="Search-close"&gt;
                        &lt;span class="lnr lnr-cross"&gt;&lt;/span&gt;
                    &lt;/span&gt;
                &lt;/form&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/header&gt;

@yield('content')

&lt;!-- start footer Area --&gt;
&lt;footer class="footer-area section-gap"&gt;
    &lt;div class="container"&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-lg-3 col-md-6 single-footer-widget"&gt;
                &lt;h4&gt;Top Products&lt;/h4&gt;
                &lt;ul&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Managed Website&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Manage Reputation&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Power Tools&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Marketing Service&lt;/a&gt;&lt;/li&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
            &lt;div class="col-lg-2 col-md-6 single-footer-widget"&gt;
                &lt;h4&gt;Quick Links&lt;/h4&gt;
                &lt;ul&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Jobs&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Brand Assets&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Investor Relations&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Terms of Service&lt;/a&gt;&lt;/li&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
            &lt;div class="col-lg-2 col-md-6 single-footer-widget"&gt;
                &lt;h4&gt;Features&lt;/h4&gt;
                &lt;ul&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Jobs&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Brand Assets&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Investor Relations&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Terms of Service&lt;/a&gt;&lt;/li&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
            &lt;div class="col-lg-2 col-md-6 single-footer-widget"&gt;
                &lt;h4&gt;Resources&lt;/h4&gt;
                &lt;ul&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Guides&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Research&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Experts&lt;/a&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;a href="#"&gt;Agencies&lt;/a&gt;&lt;/li&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
            &lt;div class="col-lg-3 col-md-6 single-footer-widget"&gt;
                &lt;h4&gt;Instragram Feed&lt;/h4&gt;
                &lt;ul class="instafeed d-flex flex-wrap"&gt;
                    &lt;li&gt;&lt;img src="img/i1.jpg" alt=""&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;img src="img/i2.jpg" alt=""&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;img src="img/i3.jpg" alt=""&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;img src="img/i4.jpg" alt=""&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;img src="img/i5.jpg" alt=""&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;img src="img/i6.jpg" alt=""&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;img src="img/i7.jpg" alt=""&gt;&lt;/li&gt;
                    &lt;li&gt;&lt;img src="img/i8.jpg" alt=""&gt;&lt;/li&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="footer-bottom row align-items-center"&gt;

            &lt;div class="col-lg-4 col-md-12 footer-social"&gt;
                &lt;a href="#"&gt;&lt;i class="fa fa-facebook"&gt;&lt;/i&gt;&lt;/a&gt;
                &lt;a href="#"&gt;&lt;i class="fa fa-twitter"&gt;&lt;/i&gt;&lt;/a&gt;
                &lt;a href="#"&gt;&lt;i class="fa fa-dribbble"&gt;&lt;/i&gt;&lt;/a&gt;
                &lt;a href="#"&gt;&lt;i class="fa fa-behance"&gt;&lt;/i&gt;&lt;/a&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/footer&gt;
&lt;!-- End footer Area --&gt;
&lt;script src="js/vendor/jquery-2.2.4.min.js"&gt;&lt;/script&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;script src="js/vendor/bootstrap.min.js"&gt;&lt;/script&gt;
&lt;script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBhOdIF3Y9382fqJYt5I_sswSrEw5eihAA"&gt;&lt;/script&gt;
&lt;script src="js/easing.min.js"&gt;&lt;/script&gt;
&lt;script src="js/hoverIntent.js"&gt;&lt;/script&gt;
&lt;script src="js/superfish.min.js"&gt;&lt;/script&gt;
&lt;script src="js/jquery.ajaxchimp.min.js"&gt;&lt;/script&gt;
&lt;script src="js/jquery.magnific-popup.min.js"&gt;&lt;/script&gt;
&lt;script src="js/mn-accordion.js"&gt;&lt;/script&gt;
&lt;script src="js/jquery-ui.js"&gt;&lt;/script&gt;
&lt;script src="js/jquery.nice-select.min.js"&gt;&lt;/script&gt;
&lt;script src="js/owl.carousel.min.js"&gt;&lt;/script&gt;
&lt;script src="js/mail-script.js"&gt;&lt;/script&gt;
&lt;script src="js/main.js"&gt;&lt;/script&gt;

</body>

Hope you can help me guys. Thank you.

How to setup automatic Databases backup in Laravel

How to setup automatic Databases backup in Laravel

As Laravel developers we need a way to back up our app’s databases somewhere for both save keeping the data and for analysis. In this post, you'll learn how to setup automatic Databases backup in Laravel

I want to share with you a simple solution that I have devised for some of my smaller projects. I have tested this method only on MySQL Databases and on a VPS, but I think it’s pretty much the same for any database.

TLDR;

The outline of my solution is as follows. There’s an artisan command which handles the backup, that runs periodically using a cron. This command makes use of the mysqldump tool that comes with all MySql installations. mysqldump dumps the given DB into a .sql and we can control where it is dumped. And that’s how my solution works. Now let’s see some code.

The Code

First off create an Artisan command like so php artisan make:command BackupDatabase. This should create a class with the name you mentioned in the command and should also have some default scaffolding for the command.

Let me explain what the above code does. Within the constructor we prepare the name of the file (line 20), then we check if there’s a folder named backups within the storage folder, if not we create it (line 21). Then we instantiate a process, with the command that we want to be executed, we also pass it other details (line 23-29).

Then in the handle method runs the process and logs the output to the application logs. This handle method is executed after the constructor by Laravel itself, so you don’t have to invoke it from anywhere.

And finally you need to setup cron, you have 2 options here, either you can call Laravel’s schedule:run command or call your backup command directly.

Conclusion

This is a pretty simple and neat solution for backing up your most valuable asset, that’s the data. You can extend this feature to do more, like attach the .sql file to an email or upload it to dropbox or where ever and so on.

Manage databases easily with Laravel Prequel

Manage databases easily with Laravel Prequel

Laravel Prequel is a Laravel package which can be used to manage databases without the need for tools like PHPmyadmin or Sequel Pro.

Laravel Prequel is a Laravel package which can be used to manage databases without the need for tools like PHPmyadmin or Sequel Pro.

What is Prequel exactly?

Prequel is meant to be a database management tool for Laravel to replace the need for separate standalone database tools like phpMyAdmin, Sequel Pro or MySQL Workbench. With its (hopefully) clear and concise UI, Prequel is to be a modern and lightweight database browser/tool ready for the web of the future. Prequel's design is purposefully based on that of Laravel Telescope because (web-)developers today have enough to learn and master already, so let's help eachother out and make sure to not add anything virtually useless to that huge pile of knowledge.

Clear and concise database management## Installation

To install follow the instructions below.
$ composer require protoqol/prequel  
$ php artisan prequel:install

When installation and publishing is done navigate to /prequel in your browser to see Prequel in action!
Updating
To update you can use the command specified below.
$ php artisan prequel:update

Issues, bugs and feature requests can be reported here!

Configuration

You might have noticed that, while publishing a config file appeared under config/prequel.php. That configuration file looks something like this.

Note that you can define PREQUEL_ENABLED in your .env file.

[  

    /*  
    |--------------------------------------------------------------------------  
    | Prequel Master Switch : boolean
    |--------------------------------------------------------------------------  
    |  
    | Manually disable/enable Prequel, if in production Prequel will always  
    | be disabled. Reason being that nobody should ever be able to directly look  
    | inside your database besides you or your dev team (obviously).  
    |  
    */
    'enabled'      => env('PREQUEL_ENABLED', true),  
      
    /*  
    |--------------------------------------------------------------------------  
    | Prequel Path : string
    |--------------------------------------------------------------------------  
    |  
    | The path where Prequel will be residing. Note that this does not affect 
    | Prequel API routes.  
    |  
    */
    'path'         => 'prequel',  
    
    /*  
    |--------------------------------------------------------------------------  
    | Prequel Database Configuration : array
    |--------------------------------------------------------------------------  
    |  
    | This enables you to fully configure your database-connection for Prequel.
    |  
    */
    'database' => [  
      'connection' => env('DB_CONNECTION', 'mysql'),  
      'host'       => env('DB_HOST', '127.0.0.1'),  
      'port'       => env('DB_PORT', '3306'),  
      'database'   => env('DB_DATABASE', 'homestead'),  
      'username'   => env('DB_USERNAME', 'homestead'),  
      'password'   => env('DB_PASSWORD', 'secret'),  
     ],  
     
    /*  
    |--------------------------------------------------------------------------  
    | Prequel ignored databases and tables : array
    |--------------------------------------------------------------------------  
    | Databases and tables that will be ignored during database discovery.
    |
    | Using 'mysql' => ['*'] ignores the entire mysql database.
    | Using 'mysql' => ['foo']  ignores only the mysql.foo table.
    */
    'ignored'      => [  
         // 'information_schema'  => ['*'],  
         // 'sys'                 => ['*'],
         // 'performance_schema'  => ['*'], 
         // 'mysql'               => ['*'],
         '#mysql50#lost+found'    => ['*'],  
     ],
     
    /*
    |--------------------------------------------------------------------------
    | Prequel pagination per page : integer
    |--------------------------------------------------------------------------
    |
    | When Prequel retrieves paginated information, this is the number of
    | records that will be in each page.
    |
    */
    'pagination' => 100,
    
        /*
        |--------------------------------------------------------------------------
        | Prequel middleware : array
        |--------------------------------------------------------------------------
        |
        | Define custom middleware for Prequel to use.
        |
        | Ex. 'web', Protoqol\Prequel\Http\Middleware\Authorised::class
        |
        */
    
        'middleware' => [
            Protoqol\Prequel\Http\Middleware\Authorised::class,
        ],
];

Clear and concise database management

The Complete Guide to Database Seeder in Laravel 6

The Complete Guide to Database Seeder in Laravel 6

You have lots of question what is seeder in Laravel 6? How to use seeder in Laravel 6? What is command to create seeder in Laravel 6? Why we have to use seeder in Laravel 6? That's all I will example in this Laravel 6 database seed tutorial.

Laravel introduce seeder for creating testing data and if you have small admin project then you can create admin user and also setting table default data.

Whenever you have admin project that don't have register page then what you will do?, I mean you need to create at least one admin user. So basically he can login and access whole admin panel. But you don't have register page on front end. you only have login page. So you can create one admin from database directly? If yes then you have to always create new admin user from directly database when you create new setup of your project. But i will suggest you to create admin seeder so you can create admin user using Laravel 6 seeder. You just fire on command to run seeder in Laravel 6.

Same things, if you have default setting configuration then you can create setting seeder and add default configuration to your database table.

In this tutorial, i will show you how to create database seeder in Laravel 6 and what is command to create seeder and how to run that seeder in Laravel 6. So you have to just follow few step get how it's done.

Laravel gives command to create seeder in laravel. so you can run following command to make seeder in laravel application.

Create Seeder Command:

php artisan make:seeder AdminUserSeeder

After run above command, it will create one file AdminUserSeeder.php on seeds folder. All seed classes are stored in the database/seeds directory.

Then you can write code of create admin user using model in laravel.

database/seeds/AdminUserSeeder.php

<?php

  

use Illuminate\Database\Seeder;

use App\User;

   

class AdminUserSeeder extends Seeder

{

    /**

     * Run the database seeds.

     *

     * @return void

     */

    public function run()

    {

        User::create([

            'name' => 'Hardik',

            'email' => '[email protected]',

            'password' => bcrypt('123456'),

        ]);

    }

}

As you can see above code, i simply write creating new user in my users table now. so you can add your code to write admin user creating. Now how you can run this seeder manually.

There is a two way to run this seeder. I will give you both way to run seeder in Laravel 6.

Way 1: Run Single Seeder

You need to run following command to run single seeder:

php artisan db:seed --class=AdminUserSeeder

Way 2: Run All Seeders

In this way, you have to declare your seeder in DatabaseSeeder class file. then you have to run single command to run all listed seeder class.

So can list as bellow:

database/seeds/DatabaseSeeder.php

<?php

  

use Illuminate\Database\Seeder;

   

class DatabaseSeeder extends Seeder

{

    /**

     * Seed the application's database.

     *

     * @return void

     */

    public function run()

    {

        $this->call(AdminUserSeeder::class);

    }

}

Now you need to run following command for run all listed seeder:

php artisan db:seed

Now i think you will understand how seeding is work and we have to use in our Laravel app.

I hope it can help you...