ajsmith_codes

ajsmith_codes

Member Since 1 Year Ago

Experience Points
13,740
Total
Experience

1,260 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
106
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 3
13,740 XP
Jun
01
1 day ago
Activity icon

Replied to Need Help With Logic And Permissions.

Oh, got it. Thanks!

Activity icon

Replied to Need Help With Logic And Permissions.

What do you mean by "Don't make it static"? I'm not very familiar with that.

May
29
4 days ago
Activity icon

Replied to Need Help With Logic And Permissions.

I finally figured it out, but it's not very pretty in my opinion.

Changed my ProjectPolicy entry to this:

public static function editProject(User $user, Project $project)
{

        $canEdit = $project->members($user)->pluck('edit_project');

        if ($canEdit->contains(1))
            return true;
        else
            return false;

}
Activity icon

Replied to Need Help With Logic And Permissions.

It's coming back empty:

Illuminate\Database\Eloquent\Collection {#1421 ▼ #items: [] }

Activity icon

Replied to Need Help With Logic And Permissions.

Here is my policy:

public static function editProject(User $user, Project $project)
{
    return $project->members->where('project_id', $project->id)
        ->where('user_id', $user->id)
        ->where('edit_project', 1);
}

And the view:

        @can('editProject', $project)
            yes
        @endcan

EDIT:

This is in Project model:

public function members()
{
    return $this->belongsToMany(User::class, 'project_members')
        ->withTimestamps()
        ->withPivot('edit_project');
}

I get 'yes' no matter what. To me, that means I'm doing something wrong in the policy. What do you think?

Activity icon

Replied to Need Help With Logic And Permissions.

I'm trying that, but it's not working. I'll keep looking at my controller and see if I can figure it out. Thanks!

Activity icon

Replied to Need Help With Logic And Permissions.

How would I reference that in a view?

Activity icon

Replied to Need Help With Logic And Permissions.

Sorry, another question about this. How would I find out if the user can update the project? I need to look in a pivot table, make sure the user is a member of that project, then pull true or false from a column called 'can_edit'.

Activity icon

Replied to Need Help With Logic And Permissions.

I think I'm going to do a mix of that and what I have. Thanks!

Activity icon

Replied to Need Help With Logic And Permissions.

Pretend I don't use it. How would you go about giving a user permission to edit a specific project? I don't want them to edit all projects.

Activity icon

Replied to Need Help With Logic And Permissions.

I will look into that.

How would I go about getting a boolean for this situation:

Referencing the pivot table, I would check that the user is a member of the project, but then I need find out if they have edit permissions.

Is this close? I can't seem to get the logic working.

    $user = auth()->user();
    
    $members = $project->members();

    $canEdit = $members->where('permission_id', 1)->where('user_id', $user->id);
Activity icon

Started a new Conversation Need Help With Logic And Permissions.

I have an app where I am using Spatie Permissions. If you're not familiar with it, it is where you can assign Permissions and Roles. They recommend you assign permissions to roles instead of users. I am not certain that will work for my situation and need some advice/guidance.

Here is what I'm trying to do:

John owns Project 123. He wants to allow Jane to edit the project. He wants Jim to have view-only rights.

When he invites them, the pivot table called project_members gets an entry that has the project_id, user_id, and permission_id. (basically a pivot table linking to three other tables)

Permission_id of 1 is "edit projects".

Permission_id of 2 is "view only".

How do I make use of this by using one view instead of two (if two, one is read-only and second is edit)?

If I were to use Roles or Permissions alone, I could just say @can('manage'). However, with the way I have it set up, that doesn't work.

Hopefully, this makes sense.

May
28
5 days ago
Activity icon

Replied to Customer Error Message For Form.

Amazingly simple!! Thanks!

Activity icon

Started a new Conversation Customer Error Message For Form.

When a user submits a form to invite a user to edit the project, I want to check that the user they are inviting is not already a member, then return a message if they are. I'm guessing this would be custom validation? If so, how would I go about that?

Here is what I have so far:

       if ($project->members->contains($user)){
            //already a member


        }else{
            $project->invite($user, $project);
             //if not, invite them
        }
May
26
1 week ago
Activity icon

Replied to Dropdown Field - Set Default Even Though Based On Variable?

Sorry, forgot to include code:

Select Role
                            @foreach($roles as $role)

                                <option>
                                    {{ ucfirst($role->name)  }}
                                </option>

                            @endforeach

                        </select>

                    </div>


                    <div>
                        <label>Select User</label>


                        <select
                            name="user"
                            class="shadow">

                            @foreach($users as $user)

                                <option>
                                    {{ $user->name }}
                                </option>

                            @endforeach
                        </select>
Activity icon

Started a new Conversation Dropdown Field - Set Default Even Though Based On Variable?

Please tell me if this is unclear. It was difficult to come up with a name for the question.

I have a form with a dropdown box. The box populates with a list of users from the database. The default is the first user in the database. Is there a way to set it to text that says "Choose user" instead?

May
20
1 week ago
Activity icon

Replied to How To Add Favicon In Laravel

This one worked for me. I couldn't get Snapey's suggestion to work on the server.

May
18
2 weeks ago
Activity icon

Replied to Access Denied For User After Deployment.

@anthonyreid I did and marked your answer as the right one. Thanks!!

Activity icon

Replied to Access Denied For User After Deployment.

@anthonyreid

Doing that gave me a different error message, so yay! Progress!

Now when I try to login I get "These credentials do not match our records"

At this point it must be my username and password for the app, right?

Activity icon

Replied to Access Denied For User After Deployment.

@anthonyreid

Yes, it does have a # in it. I'll give that a try!

Activity icon

Replied to Access Denied For User After Deployment.

@anthonyreid

I did attach the user and the user has all permissions.

Activity icon

Replied to Access Denied For User After Deployment.

@anthonyreid

Do you mean the permissions to access the database, or the file permissions for the Laravel app?

Activity icon

Replied to Access Denied For User After Deployment.

@spyworld

I get this error when I try to flush:

#1227 - Access denied; you need (at least one of) the RELOAD privilege(s) for this operation

Activity icon

Replied to Access Denied For User After Deployment.

@mvdnbrk

I entered the same values into the .env file as I did the script, so they were the same. I think everyone is confused about that. I'm not talking about a local test file. I created the usual PHP test code that results in an answer when you run it. Does that make sense? You can see it here: http://inexhaustsystems.com/test.php

I tried to clear the cache. I checked the database config file:

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

I do believe the .env file is in the correct spot, because when I change the values in it, it is showing up in the error.

No luck adding the quotation marks.

Activity icon

Replied to Access Denied For User After Deployment.

@jlrdw Good thought, but I've done that with no change.

Activity icon

Replied to Access Denied For User After Deployment.

Update:

I tried to run migrate from the command line and got the same connection error. I can't seem to figure out why I can get a connection via a PHP script with the same credentials as my .env file.

Activity icon

Replied to Access Denied For User After Deployment.

@esorone Good guess. I tried that already and same result.

Activity icon

Replied to Access Denied For User After Deployment.

@mvdnbrk They are the same credentials. When I say test script, I mean that I used this on the server:

```$database = "inexha5_hub";
```$username = 
```$password = 

```Create connection
```$conn = new mysqli($servername, $username, $password, $database);
```Check connection
```if ($conn->connect_error) {
   ```die("Connection failed: " . $conn->connect_error);
```}
  ```echo "Connected successfully";
Activity icon

Replied to Access Denied For User After Deployment.

@jlrdw It's a good try, but I did change them. :(

Activity icon

Replied to Access Denied For User After Deployment.

@esorone I tried that and got the same error. However, if I test the db connection via a PHP script, it makes the connection.

Here's my .env:

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=removed for security DB_USERNAME=removed for security DB_PASSWORD=removed for security

Activity icon

Replied to Access Denied For User After Deployment.

@mvdnbrk But I can connect if I use a test script.

Activity icon

Started a new Conversation Access Denied For User After Deployment.

Can't seem to find the answer to this one in the forums or by Googling...

After deploying to a live server, I can't seem to login to my app. I tested the db connection with a script and it was working. So, I thought maybe it's my username/password. However, when I changed the password in phpmyadmin, it still doesn't work.

Here is the error:

```SQLSTATE[HY000] [1045] Access denied for user 'hollys7_inexhaus'@'localhost' (using password: YES) (SQL: select * from users where email = [email protected] limit 1)

SQLSTATE[HY000] [1045] Access denied for user 'hollys7_inexhaus'@'localhost' (using password: YES)
May
14
2 weeks ago
Activity icon

Replied to Help! Why Is My Birdboard App Logging Two Activities?

Writing this reply to update where I"m at with this and it helps to troubleshoot. :)

I've been working on this some more and found out a few things that might lead to a solution.

When I mark a task as complete, it is basically updating the task. Therefore, it logs activity as updated_task. I would like to change the verbiage to be completed_task in this situation.

Somewhere in my program, $description is being set. I need to override that description.

May
12
3 weeks ago
Activity icon

Replied to Undefined Index - Trouble Passing Token Value From View To Controller.

It's strange, but that's the way it comes through. I didn't set it that way. Also, that is the CSRF token, which is not the one I want. Thanks for trying though!

Activity icon

Replied to Undefined Index - Trouble Passing Token Value From View To Controller.

UPDATE...

I did a var_dump of the $data array in the RegisterController I do not get the correct token passed:

array(4) { ["_token"]=> string(40) "yEnSU1GZ0mzODdbQqFxuJgVh2nrbHlyzZZtg6LFj" ["name"]=> string(4) "john" ["password"]=> string(15) "PeM#De!Ufn!Mwk2" ["password_confirmation"]=> string(15) "PeM#De!Ufn!Mwk2" }

When the user visits the page, I do see the token there in the UsersController:

public function registration_view($token)
{

    $invite = Invite::where('token', $token)->first();
    return view('auth.register',['invite' => $invite]);
}
Activity icon

Started a new Conversation Undefined Index - Trouble Passing Token Value From View To Controller.

I am trying a user invitation system using Laravel 7 auth. I followed the instructions here: User Invitation If you want to see the full code I have, it's the same as the link.

I think the problem is when I submit the form. The token the user was given is not being passed to the controller. The CSRF token is. Not sure if they are conflicting or if I'm missing something.

Form method/action:

<form method="POST" action="{{route('accept')}}">

Here is the method that is called when a user follows the email invitation to register:

protected function create(array $data) {

    $invite = Invite::where('token', $data['token'])->first();
    $invite->delete();

    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ]);
}                         

The error is occurring on the first line of that code.

ErrorException Undefined index: token

May
08
3 weeks ago
Activity icon

Replied to Read-only Vs Editing - Best Practices?

Thanks! That makes sense. The only thing I was thinking of was that the code/layout changes might be difficult to keep up with on two views vs one. However, I think I could minimize it by using templates as much as possible.

Do you know of a good resource to find answers to things like this other than forums? I guess I mean books, blogs or something.

Activity icon

Started a new Conversation Read-only Vs Editing - Best Practices?

I have a project page where a user can do the usual CRUD. I would like other users to see the project info, but not edit it.

What's the best practice here? Create a separate view where they can see the info, or add to the current view by using @can('manage')? Or is there another, better way?

Activity icon

Awarded Best Reply on Save Project Path To Linked Table In Database?

I got it to work!

I was making this way too difficult. Here's what I did to fix:

I created a variable called $path = $project->path();

Then passed it to the model:

    $project->addTask(request('text'), $path);

Then in the model,

public function addTask($text, $path)
{

    return $this->tasks()->create(compact('text', 'path'));
}

Thanks for the help!

Activity icon

Replied to Save Project Path To Linked Table In Database?

I got it to work!

I was making this way too difficult. Here's what I did to fix:

I created a variable called $path = $project->path();

Then passed it to the model:

    $project->addTask(request('text'), $path);

Then in the model,

public function addTask($text, $path)
{

    return $this->tasks()->create(compact('text', 'path'));
}

Thanks for the help!

Activity icon

Replied to Save Project Path To Linked Table In Database?

I don't this this will work then. The tasks may be created at a later time than the project. I do have that relationship already though if that helps.

Activity icon

Replied to Save Project Path To Linked Table In Database?

I think the part I'm stuck on right now is how to get the task id. The task is being created, so it doesn't have an id yet. Once it does, how do I retrieve that?

Activity icon

Replied to Save Project Path To Linked Table In Database?

@judev I changed the code to this:

public function store(Project $project, Task $task) {

    $this->authorize('update', $project);

    request()->validate(['text' => 'required']);

    $project->addTask(request('text'));

    $id = $task->id;

    Model::create([ //create  or if you want to update.
        'path' => $project->path(),  // if you want to pass the id
    ]);

    //You need to use this if you want to update column.
    $model = Model::find($id);
    $model->path = $project->path();

    return redirect($project->path());
}

But get this error:

Illuminate\Database\QueryException SQLSTATE[HY000]: General error: 1364 Field 'path' doesn't have a default value (SQL: insert into tasks (text, project_id, updated_at, created_at) values (test, 9, 2020-05-08 15:06:35, 2020-05-08 15:06:35))

Activity icon

Replied to Save Project Path To Linked Table In Database?

@judev $project->path() includes an id, so do I need to include $id? Or is $id in your code the id of the task?

Activity icon

Replied to Save Project Path To Linked Table In Database?

@judev I think that is correct. I want to store the value of $project->path(), which ends up being something like "project/id" and save to "path" column.

Activity icon

Replied to Save Project Path To Linked Table In Database?

@judev Sorry I'm confusing you. I will try to better explain. :)

The store method on the controller:

public function store(Project $project) {

    $this->authorize('update', $project);

    request()->validate(['text' => 'required']);

    $project->addTask(request('text'));

    return redirect($project->path());
}

Then calls the addTask method in the model:

public function addTask($text) {

    return $this->tasks()->create(compact('text'));
}

Currently, the only things being stored in the task table is the project_id the task is tied to and the text of the task. I can find the path anytime by using $project->path().

So, how do I save $project->path() value and send to column path in database.

Does that help?

Activity icon

Replied to Save Project Path To Linked Table In Database?

@judev Not having much luck. I think it's because I forgot that the controller calls the addTask method on the Projects.php:

public function addTask($text) {

    return $this->tasks()->create(compact('text'));
}

Knowing that, does it change the code? I tried both and couldn't get them to work. I must be missing something.

Activity icon

Replied to Save Project Path To Linked Table In Database?

@judev That sounds more like what I am looking for. I'll check it and let you know what happens. Thanks!

Activity icon

Replied to Save Project Path To Linked Table In Database?

@judev Hello! I think I was a bit unclear about what I was looking for. I know how to capture the path, I just don't know how to send it to the database. I have a column called 'path' and that is where I want to store it.

How do I send the value of $project->path() to the path column?