creativetimofficial / ct-vue-material-dashboard-laravel-pro-bs4

Vue SPA Material template connected to working Laravel REST API with the help of json:api standard
7 stars 2 forks source link

Image upload failing #14

Closed OV-Hank closed 2 years ago

OV-Hank commented 2 years ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Expected Behavior

I expect the image upload from the profile to be saved and the file location to be updated to mysql server.

Current Behavior

The file gets moved to the storage/app/users folder but then fails.

Failure Information (for bugs)

screenshot attached

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. navigate to user profile
  2. click select image
  3. select image for import
  4. click update profile

Context

running on mamp locally.

Failure Logs

from networking

Screen Shot 2022-06-03 at 3 10 28 PM Screen Shot 2022-06-03 at 3 10 53 PM Screen Shot 2022-06-03 at 3 11 22 PM

{ "errors": [ { "status": "422", "title": "Unprocessable Entity", "detail": "The profile image format is invalid.", "source": { "pointer": "/data/attributes/profile_image" }, "meta": { "failed": { "rule": "url" } } } ] }

teamupdivision commented 2 years ago

Hi @OV-Hank,

Thank you for using the Creative Tim products!

It seems like you don't generate the correct URL path for the image. In the config > filesystems, you need to add 'url' => env('APP_URL').'/storage', for the disks array, local.

If you have any other questions, please let us know.

Best, UPDIVISION Team

OV-Hank commented 2 years ago

Thanks, that seemed to do the trick.

I do have another question that I haven't been able to find an answer for after googling the last couple of days.

The items table has a user_id field. I want to make the item list page only display the items that belong to the logged in user. Where/how would I add this parameter? I've searched but the way this app is setup isn't like any of the many tutorials, stackoverflow posts I have come across.

For example on the below snapshot, user with ID 4 is logged in, he should only be able to see the last item that belongs to him and not the first 3 that belong to user with ID 1.

Thanks so much for your help!

Screen Shot 2022-06-10 at 9 30 01 AM
teamupdivision commented 2 years ago

Hi @OV-Hank,

There are multiple possibilities for your request:

  1. You can send the id of the logged user in the backend and take directly from there the associated items.
  2. You can filter the items depending on the logged user in the list function from items-service.js.
  3. You can create restrictions depending on what you want to show in Item policy, in the view function.

Please let us know if you need further assistance.

Best, UPDIVISION Team

OV-Hank commented 2 years ago

Here is what I have in the item view policy but I still am returning all items.

`
public function view(User $user, Item $item)

{

    if (auth()->user()->id === $item->user_id){
        return $user->can('view items');
    }     
}

`

teamupdivision commented 2 years ago

Hi @OV-Hank,

You also need a global scope on the model from which you can filter the returned items. You need to call it in the boot function, where if the user is authenticated and has view items permissions it returns $builder. If not, it returns the items filtered by the user id.

We hope this information will help you with your issue.

Best, UPDIVISION Team

teamupdivision commented 2 years ago

Hi @OV-Hank,

We hope we managed to help you in solving this issue.

Should you need further assistance, do not hesitate to let us know.

Best, UPDIVISION Team