learn-by-flying

learn-by-flying

Member Since 5 Months Ago

Experience Points 2,090
Experience Level 1

2,910 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 15
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

30 Aug
2 weeks ago

learn-by-flying left a reply on Mail Notifications

@janosk Thanks so much, not sure how I missed that.

29 Aug
3 weeks ago

learn-by-flying started a new conversation Mail Notifications

I am trying to grasp notifications and have then sending out correctly however I am pulling my hair hair out trying to pass data.

The goal is to send out a notification to all staff when a new post is created.

For now I am calling this off of my StaffDashboardController controller on the index so that I can just refresh the index.

public function index()
    {
       $staff = Staff::all();
       $post = Post::find(1);

    //$staff->notify(new NewAdminNewsPosted($post));
    Notification::send($staff, new NewAdminNewsPosted($post));

        //Step 1. Get all the pertinent information on the admin homepage.
            $posts = Post::all();

        return view('back-views.dashboard-staff.dashboard')->with('posts', $posts);
    }

And I have the following function within my NewAdminNewsPosted file within App/Notifications

use Queueable;

    public function __construct()
    {
        //
    }

    public function via($notifiable)
    {
        return ['mail'];
    }


    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->from('[email protected]', 'Buehler - ESD Alerts')
            ->subject('ESD: News Posting')
            ->line('A new news item has been posted, we thought you may want to check it out. ')
            ->action($notifiable->post, url('/'))
            ->line('Thank you for using our application!');
    }

For the life of me, I however cannot manage to get the $post->id to populate or the $post->post_title, I have read the documentation on this and watched a few youtube tutorials but cannot figure this one out.

Any help or points in the right direction would be greatly appreciated.

Thanks,

Tom

23 Aug
3 weeks ago

learn-by-flying left a reply on Return $next($request) With Parameter

To update the thread, I was able to flash the message, I am using the following:

//Let all admin's through
        if($staff->isAdmin == 1)
        {
            session()->flash('warning', 'You are being granted access by your Admin status and not based on your role.');

            return $next($request);
        }

        return redirect()->back()->with('error', "Access error, you do not have access to \"$friendly_name\".");

learn-by-flying left a reply on Return $next($request) With Parameter

Yes, but the opposite, in your example Bob as an admin would have access through his admin flag and not his user role.

After digging in the documentation I should be able to add to the session data.

learn-by-flying left a reply on Impossible To Disable Register In Laravel 5.8!

It might be a better question as to why you are turning off register instead of possibly hiding it, you will need the functionality to add users unless you have another controller/function working with the users model.

To just disable the route @nakov answer is correct.

I would leave open, but redirect it with an error explaining why the route is turned off instead of causing a 404 error.

learn-by-flying left a reply on Is There Any Series Or Episode On Multiauth ?

@babarkhan if you are looking to create two user sets there is this set of videos on YouTube by DevMarketer.

Very well done and what I used to get started.

https://www.youtube.com/watch?v=iKRLrJXNN4M

learn-by-flying left a reply on User Model Best Practices

I echo what @jlrdw says, also keep in mind that a lot of the functionality in deeper parts of the auth are not directly relayed to you when creating the authentication scheme for the first time using the make::auth command.

An example of this is customizing the password reset logic and so forth.

Before I would ever start customizing (which I have), run through a hello world app with what you are trying to customize before placing the customization's into a development app.

Also, you can always pull in information from other models and especially with the hasOneThrough() or hasManyThrough().

learn-by-flying left a reply on Return $next($request) With Parameter

Thanks for the reply @jlrdw

Within the system each staff member has a role with a certain set of permissions, this allows/blocks access through middleware to certain parts of the system.

Staff members can also be tagged as an admin which gives them access into the admin portion of the interface to control items such as deep permissions management but also gives them access into the entire system as even if Staff John Smith is a technician, and the page he is on requires technician II access, because John is an admin he can access.

The goal here as requested is to visually alert admins that they are accessing parts of the system which are outside of their role however due to their admin access they can proceed. This also then kicks off audit logging to understand why an admin may have overridden something.

Within the system I have two guards functioning protecting the users on the front end and then staff on the back side of the app. User's have their own permission roles which are assignable based on status coming from our ERP but limited in functionality scope to only user functionality such as changing organizational names, updating tax certificates etc.

I am not receiving any errors with the:

return redirect()->back()->with('error', "Access error, you do not have access to \"$friendly_name\".");

but if I comment out the ->with() as in:

if($staff->isAdmin == 1)
        {
            return $next($request)/*->with('warning', 'Access is being granted on admin status, your role is not granting.')*/;
        }

I receive a Method Illuminate\HTTP\Response::with does not exist.

Thanks,

learn-by-flying started a new conversation Return $next($request) With Parameter

Hello All,

I have searched and searched, however I cannot find anything.

Background: I have a role based access system implemented through middleware however I also let admin's override their roles access but want to do so with a warning so fare I have my middleware all working except with the ->with statement after the $next($request).

Any ideas on how to properly implement this?

//Let all admin's through

        if($staff->isAdmin == 1)
        {
            return $next($request)/*->with('warning', 'Access is being granted on admin status, your role is not granting.')*/;
        }

        return redirect()->back()->with('error', "Access error, you do not have access to \"$friendly_name\".");
09 Jul
2 months ago

learn-by-flying started a new conversation Send HTTP Request Through Other Server

I have a very interesting question of possibility regarding sending a HTTP request through a private network and not the public internet. Honestly I have no idea where to start looking for help so I am posting in a few different places.

I have two servers, 1 & 2 with #2 being connected to our corporate VPN but does not publicly face the internet. #1 hosts my laravel application and I need to call a web service which runs on our corporate network.

Is there a way which I can specify when a controller asks for a json request from an internal only address to route through server #2?

Ideally I would not connect #1 to the VPN unless absolutely necessary.

Server #1 is Centos 7 running Plesk Server #2 is Windows 2016

Thanks,

29 May
3 months ago

learn-by-flying left a reply on Where Should Basic Logic Be Placed?

@martinbean & @devfrey thank you very much, I've got plenty to keep going.

learn-by-flying started a new conversation Where Should Basic Logic Be Placed?

Hi Everyone,

Have successfully gotten laravel up and running, published the hello world app and starting to dive deeper into a basic production prototype; however I am at a loss regarding best practice on some simple logic and where to place these items:

-IP Blocking, traditional I would have this within the html header for the page so that users not on a specific IP would be re-directed to another page (normally my "how to connect to the VPN"). Is it best practice or appropriate to place these specific small scripts in a blade file and then call them with the @yield method?

-Is there a way to define some master global variables for the entire framework?

Thanks,

09 May
4 months ago

learn-by-flying left a reply on Two Tables From One Controller

@punksolid,

Thank you very much, I must have missed this and have added laravels default time stamp columns to the table and everything is working.

08 May
4 months ago

learn-by-flying started a new conversation Two Tables From One Controller

Hello everyone, I am brand new to laravel and frameworks in general and have hit a wall in my googlefu and need some assistance with the following.

Background: I am working on my Hello World laravel application and working through the laravel from scratch tutorial on Laracasts and following a laravel from scratch tutorial from YouTube (https://www.youtube.com/watch?v=EU7PRmCpx-0).

I have created a table called Posts, and now I am working on extending the functionality of this table so that each time a user edits a post the prior title and body of the post is saved in the posts_update table.

I have two models (Posts.php & Post_Update.php), and a single PostsController.php, from the edit.blade.php I am utilizing the [email protected] function which looks like this:

public function update(Request $request, $id)
    {
        //Validate the request
        $this->validate ($request, [
            'post_title' => 'required',
            'post_body' => 'required'
            
        ]);
        //Determine the post ID to use
        $post = Post::find($id);
        
        //Create the Post_Update Object
        $post_update = new Post_Update;
        
        //Storing the Post history
        $post_update->user_id = auth()->user()->id;
        $post_update->post_id = $id;
        $post_update->prior_post_title = $post->post_title;
        $post_update->prior_post_body = $post->post_body;
        $post_update->save();        
        
        //Store the edited post in the post table
        $post->post_title = $request->input('post_title');
        $post->post_body = $request->input('post_body');
        $post->save();
        
        //Returning to the post home, with a success message that we have created. The message is telling the index then overriding the default success message. 
        return redirect('/posts')->with('success', 'Post Updated');
    }

and have brought in both models at the top of the PostsController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
//Bring in the model
use App\Post;
//Posts Update model
use App\Post_Update;

class PostsController extends Controller
{

Post_Update.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post_Update extends Model
{
    //Table Name - Can be changed if needed. 
    protected $table = 'posts_update';
    
    //Primary Key
    public $primaryKey = 'update_id';
    
    //Create the timestamps
    public $timestamps = true;
}

Posts.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    //Table Name - Can be changed if needed. 
    protected $table = 'posts';
    
    //Primary Key
    public $primaryKey = 'id';
    
    //Create the timestamps
    public $timestamps = true;
}

However when I attempt to run the function, I am receiving the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into `posts_update` (`user_id`, `post_id`, `prior_post_title`, `prior_post_body`, `updated_at`, `created_at`) values (1, 4, New Post, <p>I am a new post.&nbsp;</p>

<p>&nbsp;</p>

<p><em><strong>Edit, I am the update.&nbsp;</strong></em></p>

<p>&nbsp;</p>

<p><em><strong>Another Update. 123</strong></em></p>

<p>&nbsp;</p>

<p><em><strong>Another update.&nbsp;</strong></em></p>, 2019-05-08 17:34:15, 2019-05-08 17:34:15))

What I cannot understand is that even though I am referencing $post_update-> calls the function is attempting to write to the columns updated_at and created_at even through they are not called out.

My questions are:

Can I use this approach to write to two tables?

Is there a better method than the one I am using once I have resolved the errors?

I have explored trying to run two functions from one form however that is not allowed.

Thanks very much for your assistance.