movepixels

Member Since 3 Years Ago

Experience Points
6,670
Total
Experience

3,330 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
2
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.

  • Community Pillar

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

Level 2
6,670 XP
Mar
05
3 days ago
Activity icon

Replied to Laravel API Security

Just a follow up.

Seems problem was the paths.

I set mine to

'paths' => ['v1/*'], // api.site.com/v1

    'allowed_methods' => ['GET, POST, PUT, PATCH, DELETE, OPTIONS'],

    'allowed_origins' => [env('APP_FRONTEND')], // beats changing this for dev / testing / production 
Activity icon

Replied to Laravel API Security

Adding in your suggestion blocks every request now.

cors.php // Using Laravel 7 fruitcake cors package

'paths' => ['*'],

    'allowed_methods' => ['GET, POST, PUT, PATCH, DELETE, OPTIONS'],

    'allowed_origins' => ['*.dev.xyz'], //local testing currently

    'allowed_origins_patterns' => [],

    'allowed_headers' => [
        'Accept',
        'Authorization',
        'Content-Type',
        'Cookie',
        'DNT',
        'Origin',
        'User-Agent',
        'X-Requested-With',
    ],
    'exposed_headers' => [
        'Accept',
        'Authorization',
        'Origin',
        'Content-Type',
        'X-Requested-With',
    ],

    'max_age' => 0,

    'supports_credentials' => false,

Dev tools simply says CORS error InvalidAllowOriginValue

Request URL: http://api.dev.xyz/v1/stats/count Referrer Policy: strict-origin-when-cross-origin

Activity icon

Started a new Conversation Laravel API Security

I have a Laravel back-end API which is meant / intended for my website application to use. Its a public API in the sense that parts of the website will be accessing the API without login requirements.

So for example anyone can go to the site click"rates" and it will make the API call and return rates, in the sense its public / no auth needed since this part of the site is public.

But how can i prevent other people / sites from simply making the same request to that API endpoint and highjacking the data from my server for their use?

Basically I would like to API accept requests that only come from my website.

The secured API endpoints are protected when a user logs in and JWT's come into play.

Feb
20
2 weeks ago
Activity icon

Started a new Conversation Odd CORS Issues

I am building an image uploader. Pretty straight forward.

Odd thing that makes no sense is it only works maybe 10% of the time.

I can upload an image, repeat the process and next time I get CORS error => Cross Origin Resource sharing error: MissingAllowOriginHeader

I am simply testing with 3 images on both a server and localhost. Issue happens on both servers, using same images.

Frontend is a Vue app ( http://site.com ) makes request to laravel backend ( http://api.site.com )

Laravel has the CORS package => composer require barryvdh/laravel-cors

And config set like:

'supportsCredentials' => false,
    'allowedOrigins' => ['*'],
    'allowedHeaders' => ['*'],
    'allowedHeaders' => ['*'],
    'allowedMethods' => ['*'],
    'exposedHeaders' => ['*'],
    'maxAge' => 0,
    'hosts' => ['*']

This is frustrating since it works then it wont and I am not changing any code. Upload works, upload exact same image again it fails so I have no clue where to begin so any help, insight would be greatly appreciated.

Thanks all

Feb
16
2 weeks ago
Activity icon

Started a new Conversation Images And Sizes Database Structure

Just a question on what is best approach, not how to actually do the functionality.

Scenario: User uploads image and details are stored in "media" table ( path to S3, file details and such)

Now this image gets resized to various sizes (main, thumb, original) so the question is where to store these records?

Option / idea 1: Add a parent_id to media table so the resized / children records are stored in same table referencing the id as parent_id.

Option / idea 2: Create a new table "media_files" or some name which hold the resized images records and references back to media_id.

Both pretty much same idea but use 1 table or 2?

Side note, the media might be a morph since it could in theory hold users avatar, gallery images, videos, and so on so the table could be a universal storage table so I might have answered my own question since Scenario 1 seems more scalable.

But still I ask the community.

Thanks :)

Feb
15
3 weeks ago
Activity icon

Started a new Conversation Cache API Resource

I am wondering how can I use 'Cache::remember' on an API Resource?

My setup is pretty modular for the example of a users Profile in the sense that the Profile is made up of 10 - 15 separate Models

So basic idea is from UsersController:

public function show(Request $request, Profile $profile)
{
    // RETURN FULL PROFILE FORMATTED RESOURCE
    PublicProfileResource::withoutWrapping();
    return new PublicProfileResource($profile);
}

And the resource is:

$response = [
      'type' => 'bio',
      'attributes' => $attributes,
      'relationships' => [
        'rates' => new PublicRatesCollection($this->rate),
        'contact' => new PublicContactResource($this->contact),
        .... and 15 other as above making up the users complete profile

return $response;

Everything in terms of fetching the data and returning the resource is working, but since the profile is viewed about 1000:1 update it only makes sense to Cache the full PublicProfileResource($profile);

I thought to before passing $profile to the Resource to manually build a full complete $query, Cache the results then pass that to the Resoure but each individual query still gets executed when calling as above

So second attempt controller method looked like:

public function display(Request $request, Profile $profile){

	$key = $profile->slug . '_profile_cache';

	$data = Cache::remember($key, 60, function () use($request, $profile){
	   // getPublicProfile is a hardcoded query that already includes all the individual Models ( rates, contact and the other 15)
		return $profile->getPublicProfile($request, $profile);
    });

	// RETURN FULL PROFILE FORMATTED RESOURCE
    CachePublicProfileCollection::withoutWrapping();
    return new CachePublicProfileCollection($data);

}

But the problem, is the individual queries still get executed inside the Resource even when the data is cached and passed

        'rates' => new PublicRatesCollection($this->rate), // triggers a query yet the rate has been passed
        'contact' => new PublicContactResource($this->contact), // triggers a query yet the contact has been passed

Any ideas?

Jan
25
1 month ago
Activity icon

Replied to Add UUID To All Records

Yes that worked, now problem is saving fails!

$profile->ProfileAttribute()->attach($input);

My guess is because it has no id / primary key. Even though this works for all my other models with UUID as primary key in BaseModel:

static::creating(function($model){
	$model->{$model->getKeyName()} = (string)$model->generateNewId();
});
Activity icon

Replied to Add UUID To All Records

I will just do it direct with a SQL query.... much easier.

UPDATE profile_attribute SET id = UUID();
Activity icon

Replied to Add UUID To All Records

its a pivot table (currently working, as a request I now need to add the id to the existing table)

profile_id (CHAR36) attribute_id (CHAR36) question (VARCHARS) and timestamps

I am not running migration. ID added via mySQL workbench.

Its finding the ID col addition since its adding the UUID, problem is every ID is exactly the same

So basically i want to get all records and add a UUID to the ID col for each record.....

Activity icon

Started a new Conversation Add UUID To All Records

Not sure why this is not working. I need to add an id to existing pivot table. So there is currently no "id" column so I add that to the db.

I added "id" to the relations ->withPivot('id', 'question')

Now this set all id's to the same value


$records = ProfileAttributes::all();
try{
	DB::beginTransaction();
	foreach($records as $record){
                $record->id = Uuid::uuid4();
                $record->save();
	}
	DB::commit();
} catch(Exception $e){
	DB::rollback();
}

  // foreach ($records as $record) {
  //     $record->id = Uuid::uuid4();
  //     $record->save();
  // }

How can I simply add a column to the db and then run a function to set the id as a UUID?

Should not take hours of trying to sort this foolishness out......

Help please :)

Jan
21
1 month ago
Activity icon

Started a new Conversation Pivot Table Morph Issue

I have a "Reviewables" Trait that simply keeps track of items a user has updated / changed and then a moderator can review these changes for approval / dismiss type thing.

So basically the reviewable table saves a review_id (record in question to review) and review_type (what model is the record for)

All works fine as it stores the review_type as expected like so:

App\Models\Profile App\Models\Posts App\Models\Tasks and so on so thats all good and dandy until it hits a pivot table.

I have a areas_posts (yes it coded in the belongsToMany since it is not standard naming, and has additional fields of data) but anyways when it saves a Reviewable the review_type is => Illuminate\Database\Eloquent\Relations\Pivot

It should be I would hope to be App\Models\Posts or App\Models\Areas so it could be tracked back to the correct record but Illuminate\Database\Eloquent\Relations\Pivot is of no use since it has no defining name to reference.

Code is realy of no use since it only shows the function used to save a "reviewable" but perhaps might be of some use:

Reviewable::new($record->area_id, $record, $profile->id, $note = null);

Reviewable::new($id of association, $record is full Model object, other referencing id if passed, $note = null);

Any ideas how to get the referencing model name as the rest?

Jan
19
1 month ago
Activity icon

Replied to Laravel 6 Image Validation Failure

Oddly enough it turns out my version is different.

On my v 6.0.4 some of the types are missing....

My source code looks like:

public function validateImage($attribute, $value)
{
        return $this->validateMimes($attribute, $value, ['jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']);
}

while original GitHub source has the 'jpg' type included

public function validateImage($attribute, $value)
{
        return $this->validateMimes($attribute, $value, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']);
}

Good looking out!

Activity icon

Replied to Laravel 6 Image Validation Failure

For the sake of it this is the data / log of the info before the rules() in the formRequest

array (
  'media' => 
  Illuminate\Http\UploadedFile::__set_state(array(
     'test' => false,
     'originalName' => '17033.jpg',
     'mimeType' => 'image/jpeg',
     'error' => 0,
     'hashName' => NULL,
  )),
)  

The front-end completely separate and is working 100% on live site using laravel 5.8 API backend and its been running for 2 years with zero issues. Its only now after upgrading to 6.0 are the uploads no longer accepting the image rule. I upload the exact same image over and over, it will upload if i remove "image" from the rules, tells me its not an image when its added back in. Its clearly an image. The front-end has file validation in place also so if i select a pdf, doc, anything other than an image the upload will not process and will not even attempt to send the file to the server unless its a valid image format. Its only when image rule is left inplace does it now fail.

I will simply stick with mimes array and consider this closed because its rather foolish to investigate this any further

Activity icon

Replied to Laravel 6 Image Validation Failure

not using jQuery or anything like that, but still should not make any difference since if I remove image from the rules or skip the formRequest it works 100% and the 5.8 version works fine, 6.0 untouched fails so has noting to do with frontEnd since Laravel is simply an API backend so the data being sent has not changed, same format, same form sending the data so thats not the issue, but thanks all the same for your time

Activity icon

Replied to Laravel 6 Image Validation Failure

Correct on the redundancy fact, I was just wondering if there was a specific failure based on the code. Just because it is as you stated it redundant, but still so it worked unchanged in 5.8 then fails in 6.0 yet simply putting the redundancy fact aside and possibly being sloppy code, it should work. If I remove the mimes type it still tells me my jpg, or png is invalid and not an image.

return [
      'media' => [
        'required',
        'image'
      ],
    ];

Same error Is not an image.

Proper coding format:

return [
      'media' => 'required|image'
];

Same error still telling me my jpg image is not an image

Activity icon

Started a new Conversation Laravel 6 Image Validation Failure

I just recently upgraded an existing app to Laravel 6 and testing everything out and my image upload validation now fails.

Its currently working fine on live production site, zero changes to existing controller and formRequest but getting error => The media must be an image

I am uploading an image and the formRequest rules are:

public function rules()
{
    return [
      'media' => [
        'required',
        'image',
        'max:3072',
        'mimes:jpeg,png,jpg',
        Rule::dimensions()->minWidth(700)->minHeight(500)
      ],
    ];
  }

So it worked in 5.8 but fails in 6.0

If I simply by-pass the formRequest and skip that step the controller handles the upload with no errors so the upload functionality / saving / resizing all works fine.

Its simply when passing the request thru the formRequest it fails. If I remove "image" from rules array Laravel detects the file is or is not an specific mime type, size and dimensions but will fail if the image rule is added.

Any ideas?