movepixels

movepixels

Member Since 1 Year Ago

Experience Points 3,010
Experience
Level
Lessons Completed 2
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

11 Jan
1 week ago

movepixels started a new conversation Query Help

I need some assistance as how to get a list of available dates. Try to explain what I need so hope this comes across clear. I build an array of the next 10 weeks (Sun thru Sat) that will get be used as a select input of dates to select from. Now each date(week) has a limit of 25 spots so I have a pivot table of event_user which holds the event_id, user_id, date, (other fields not relevant) So i need to build a query that works with each of the dates so if that date has 25 spots it gets a disabled property so any user can't select that date, but still shows in the select options.

I could loop thru each date key from the array and manually if count < 25 do something else type setup but hoping there was a cleaner way.

Current date array looks like:

0: ["January 6th 2019 to January 12th 2019"]
1: ["January 13th 2019 to January 19th 2019"]
2: ["January 20th 2019 to January 26th 2019"]
3: ["January 27th 2019 to February 2nd 2019"]
4: ["February 3rd 2019 to February 9th 2019"]
5: ["February 10th 2019 to February 16th 2019"]
6: ["February 17th 2019 to February 23rd 2019"]
7: ["February 24th 2019 to March 2nd 2019"]
8: ["March 3rd 2019 to March 9th 2019"]
9: ["March 10th 2019 to March 16th 2019"]
10: ["March 17th 2019 to March 23rd 2019"]

So I eventually need a way to know if any of these dates has 25 users for this event in the event_user table, if so I need to add a 'disabled' => true to that date key.

Any insight, help, ideas will be greatly appreciated. Thanks!

Dave

05 Jan
2 weeks ago

movepixels left a reply on Polymorphic Relations Help

I have never set up a Polymorphic relationship and reading the Laravel docs sounds complicated so not sure where to even start. The basics seem simple enough for Comments on Photos and Videos, but my setup seems much more advanced.

Found a few posts online for similar situations:

https://stackoverflow.com/questions/40531901/laravel-5-3-different-fields-per-user-role-type-how-to-implement-this-using-poly

and

https://www.reddit.com/r/laravel/comments/2tia9i/how_do_you_design_models_for_different_types_of/

Any ideas?

Thanks,

Dave

movepixels started a new conversation Polymorphic Relations Help

I am in the process of building a multi role based application and wondering if a Polymorphic Relation setup would make sense here.

All users will only have one Role, such as Admin, Member, Employee, Employer. So they can only be 1 of those and this will never change.

Problem is Admin User needs like 5 fields in db, Member ~10 fields, Employee~15, Employer ~30+ fields. So the idea of having 50+ fields for the User makes no sense since never will they all be needed for any particular User of any Role.

Could do a User hasOne (Member, Employee, Employer, Auth) Model / table, keeping all common fields like name, id, password, email, role_id in the users table, and individual tables for each roles fields but that seems also like a major mess.

So just curious what is the best way to approach this? Ideas, suggestions? What you have done and how it made sense to do it that way?

Thanks all!

Dave

11 Nov
2 months ago

movepixels left a reply on Laravel API Routes

I ended up going an alternate way. In RouteServiceProvider.php :

protected function mapApiRoutes()
    {
        Route::domain(env('API_ENDPOINT'))
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }

But it accomplishes the same thing. Your way is correct and its also did work!

Thanks for your time.

Dave

movepixels started a new conversation Laravel API Routes

I am trying to make the laravel api routes go to a subdomain but cant seem to find anything that solves what I am trying to do.

My front end needs to point to api.site.com/v1

My routes api.php file wraps everything like so:

Route::group(['domain' => 'api', 'prefix' => 'v1'], function () {  
...all the site routes / endpoints 

But I can not seem to get that going.

Any help / insight would be greatly appreciated.

Thanks,

Dave

07 Nov
2 months ago

movepixels started a new conversation User Registration Flow Help

I need so help on what would be the best way to handle user registration with selecting a subscription or without. The user can click register and sign up, or they might have selected a plan(saved to a cookie) and on registration that cookie is used to create a plan for the user.

But all payments are handled on the authenticated side of things. There is no payment or check out prior to registration.

Terms of Use prohibit the usage of Stripe / Braintree Cashier Integration, so this is not an option.

And a user might have "ads" so I am wondering on the relationship for this. I have: User->hasMany->Ad (user might post sever ads in different categories) Ad->hasMany->Subscription (might have a basic plan, and also an add on for extra something) Subscription->belongsTo->Plan (plan_a, premuim, basic plans)

Any insight / ideas how to handle this would be greatly appreciated.

Thanks, Dave

05 Nov
2 months ago

movepixels left a reply on Validation Question

All good, my array was formatted wrong!

movepixels left a reply on Validation Question

OK I have this:

public function rules()
  {
    $filters = [
      '_1977,
      aden,
      brannan,
      brooklyn,
      clarendon,
      earlybird,
      gingham,
      hudson,
      inkwell,
      kelvin,
      lark,
      lofi,
      maven,
      mayfair,
      moon,
      nashville
      perpetua,
      reyes,
      rise,
      slumber,
      stinson,
      toaster,
      valenci,
      walden,
      willow,
       xpro2'
    ];

    return [
      'class' => [
        'nullable',
        Rule::in($filters),
      ]
    ];
  }

All fail unless class = null, if any of the $filter values is sent as the 'class' if fails with error:

{field: "class", msg: "The selected class is invalid."}

movepixels started a new conversation Validation Question

How would you properly validate a field than can be null, but if not null and has a value then that value must be in|(my array of allowed values).

Thanks,

Dave

04 Nov
2 months ago

movepixels started a new conversation Trying To Get Cookie Value.

Laravel is serving only as a backend API, with Nuxt being the front end. I set a cookie key => value on the front-end, and inspect dev-tools and sure enough it is there. But I can not access it, or doing it wrong since my value is null, empty in laravel.

I followed this but nothing:

https://pineco.de/accessing-front-end-cookies-laravel/

How can I access front-end cookies in the backend?

Thanks, Dave

01 Nov
2 months ago

movepixels left a reply on Find Neighbors

Thanks guys for the insight will give it a try!

Dave

movepixels started a new conversation Find Neighbors

Is there a method or functionality in Laravel to find the record before and after a record?

Example: display a page / pagination Query database with whatever params and say return 25 records. Click on say the 6th record you go to view that page but you want to say to the user Next Profile / Previous Profile how would you then from the original query get record #5 for previous and #7 for Next?

CakePHP has a findNeighbours() but wondering if there is something similar for Laravel or how would be the best way to solve this issue?

Thanks,

Dave

movepixels left a reply on Why Model Does Not Exist?

My bad, JS coding all day ES6 so left out function

But works as needed!

Thanks,

Dave

movepixels started a new conversation Why Model Does Not Exist?

I have my relations set as Agency hasMany Profile and Profile belongsTo Agency.

This throws error of model does not exist:

$data->agency = Agency::where('id', $data->agency_id)->with(['Profile'] => ($query) use ($data) {
          $query->where('id', '!=', $data->id);
        })

Yet using without the closure like so:

$data->agency = Agency::where('id', $data->agency_id)->with(['Profile'])->first();

Works just fine so the model is connected via relationships just fine. Only when I try to say get all Profiles for this Agency except the current profile being viewed it tells me NO!

Any thoughts? Ideas? Thanks,

Dave

30 Oct
2 months ago

movepixels started a new conversation Delete Uploads

What is the best way to handle automatic deletion of files if deleting the record?

Example very minimal for this example like a photos table with some basic fields id, location(path to the upload file).

When I delete id = 7, I need to delete the file from "location" value also. So there are no straggling uploaded files that belong to no record.

I was thinking of using in the Photo.php model using the deleted hook.

public static function boot()
    {
        self::deleted(function($model){
            // record has been deleted so its now safe to delete the files related to this record
        });
    }

Thanks,

Dave

22 Oct
3 months ago

movepixels left a reply on FormRequest / Model

What do you need access to the $profile variable for in your form request?

The validation needs to use the profile_id and I can't use Auth->User->Profile type set up since in this case it may not be the actual owner of the record making the edit. The validation has a custom Rule for unique but its unique to the record being saved, not to the user. Like Jeff has a record and say car is Audi, another of Jeff's record has Audi fine. But Jeff can not have Audi and Audi in the same record.

movepixels started a new conversation FormRequest / Model

How can I access the Model info in a FormRequest when the controller is using Route Model Binding?

My controller looks like:

public function store (FormRequest $request, Profile $profile)
// code

But inside the FormRequest how can I access the $request->some_key, and / or the $profile model?

Thanks,

Dave

15 Oct
3 months ago

movepixels left a reply on Query 2 Tables

Works for me! Thanks for your time and assistance.

Dave

movepixels started a new conversation Query 2 Tables

What I am trying to do is at registration I need check 2 tables for the 'slug' for the user so obviously it has to be unique to the user table, and I have a restrictions table so user can also user banned words, offensive and general stuff like that.

User query looks like:

$valid = !DB::table('profiles')->where('slug', $value['value'])->select([$same])->first();
return response()->json(['valid' =>  $valid ]);

But how can I add on the same thing except different table and where('name', 'like', '%' . $value['value'] . '%')

Thanks,

Dave

30 Sep
3 months ago

movepixels left a reply on Can Localhosted Laravel App Connect To Remote Database?

I will reference the links provided. Thanks guys, looks interesting to SSH tunnel.

movepixels started a new conversation Can Localhosted Laravel App Connect To Remote Database?

I was wondering if I could build an an admin interface to run locally on my machine but actually conncet to a live remote server / database?

I would like to keep the actual admin area to be completely offline and administered via my app on my local computer.

If so is there any docs on this / tutorials / guides or if anyone knows how this would be configured.

Thanks, Dave

29 Sep
3 months ago

movepixels left a reply on Distinct Query

I went with ->unique collection.

Works as needed :)

Thanks.

movepixels started a new conversation Distinct Query

I am trying to query distinct, but because of the params conditions I am getting duplicate records for a user.

Situation: User has Profile and the profile can be listed under many areas (cities) via areas_profile pivot table. So a user ( Say Johnny) can be listed in Los Angeles, or Long Beach, so if a regular user clicks Los Angeles presto Johnny is listed there, same with Long Beach. All is good.

Problem: User clicks on California it pulls all the area_id's for California and pulls all profiles for anyone in California. Johnny is listed under both. So this query below works up-to a certain point. Johnny appears once in the California records as expected.

$users = DB::table('profiles')
            ->join('area_profiles', 'profiles.id', '=', 'area_profiles.profile_id')
            ->join('photos', 'profiles.id', '=', 'photos.profile_id')
            ->select($fields)
            ->whereIn('area_profiles.area_id', $parent)
            ->where('area_profiles.active', true)
            ->where('profiles.completed', true)
            ->where('photos.sort', 1)
            ->distinct()
            ->get();

But if Johnny says he is visiting Los Angeles and has a date selected area_profiles.travel is true for 1 record and false for the Long Beach record making them no longer distinct. So Johnny's profile appears twice under California.

How can I make it so that no matter what the profile_id, no matter what the conditions are make Johnny distinct?

Or after the find remove all duplicate profiles where the id is the same?

Thanks,

Dave

movepixels left a reply on Query Help

Yes $parent is an array of either a single area_id if Los Angeles or a full array of all area_id's if someone clicks on California it pulls all area_id's in California's area_id's.

Its actually working....

My bad I forgot to include an extra parameter in the query.

Thanks all the same for the effort :)

Dave

movepixels started a new conversation Query Help

I am trying to do a query based on these params / conditions.

The site has a database table of "areas" consisting of a nested table of countries / states or regions/ and cities so the user can select Los Angeles ( say area.id = 123) so there is a pivot table called area_profiles that stores profile_id and area_id.

Now when a regular user visits the site and clicks on Los Angeles I want to pull all users (Profiles) in area_id = 123 but with conditions that the profile.complete = true and that area_profiles.active = true (user can have many areas but select to have 1 active at a time)

Query ends up like so: select profiles., area_profiles. from profiles inner join area_profiles on profiles.id = area_profiles.profile_id where area_profiles.area_id in (123) and area_profiles.active = true and profiles.completed = true

From this query builder:

$profiles= DB::table('profiles')
            ->join('area_profiles', 'profiles.id', '=', 'area_profiles.profile_id')
            ->select('profiles.*', 'area_profiles.*')
            ->whereIn('area_profiles.area_id', $parent)
            ->where('area_profiles.active', true)
            ->where('profiles.completed', true)
            ->get();

But always zero results. I have 50 dummy accounts, all active, completed (marked true) and all set to an area_id of 123.

Basicaly in english I want to say get all profiles when the profile has a record in that area of Los Angeles if that profile is complete and that its an active profile_area.

Anyone see where I am going wrong?

Thoughts? Suggestions?

Thanks,

Dave

10 Jul
6 months ago

movepixels started a new conversation Conditional Validation

I am trying conditional validation in a FormRequest like so:

namespace App\Http\Requests\Schedule;

use App\Http\Requests\Request;
use App\Http\Requests\Response;



class FormRequest extends Request {

public function rules() 
  {

    $rules = [];

    \Log::info('sun_start below');
    \Log::info($this->attributes->get('sun_start')); // logs nothing


    if ($this->attributes->get('sun_start') == '00:30') {
           \Log::info('I never see you'); // never seen when I set the sun_start value to 00:30
          $rules['end_date'] = 'required|different:sun_start';
    }

    if (in_array($this->attributes->get('sun_end'), $hours)) {
          $rules['start_date'] = 'required|different:sun_end';
    }

    return $rules;
}

Anyone see where I am going wrong? Basically a user selects from available hours, if sun_start or sun_end is selected then it must have the matching start or end hour, and must be different. So both can not start and finish at the same time, and if one is selected then both are required and different. Laravel 5.5

Thanks,

Dave

09 Jul
6 months ago

movepixels left a reply on Relationship Help

Thanks,

I will work on it and let you know how it goes.

Much appreciated!

Dave

08 Jul
6 months ago

movepixels left a reply on Relationship Help

Thanks,

I currently have this, your pivot sounds like a better options so wondering how would I translate what I currently have into something like you have suggested?

Profile Model:

public function Company()
  {
    return $this->belongsTo('App\Models\Company')->with(['Country', 'State', 'City']);
  }

  public function User()
  {
    return $this->belongsTo('App\Models\User');
  }

Company model:

public function User()
  {
    return $this->belongsTo('App\Models\User');
  }

  public function Profile()
  {
    return $this->hasMany('App\Models\Profile');
  }

User model:

public function Profile()
{
   return $this->hasOne('App\Models\Profile');
}

// User may infact have many Companies
public function Agency()
{
   return $this->hasMany('App\Models\Company');
}

I'm just wondering how I would connect the Profile?

In my head I see: User has One Profile since its an individual User might be a Company and then that company might have many profiles, hence the pivot only for users with a Company?

Thanks for the assistance, making more sense, but still thinking does this link everything in properly?

Dave

07 Jul
6 months ago

movepixels started a new conversation Relationship Help

I am trying to figure the relationship for models for this situation and looking for some advice from anyone who might have a good idea.

Overview the site is for "Users" and can have / belongTo a "Role" where a role is determined when they sign up as an Individual or as a Company.

So if a User signs up as an Individual they can have 1 "Profile" which is just about them since there is no business info needed,

If a User is a Company then they need a CompanyProfile since its completely different from what an Individual would have, but each CompanyProfile will have many Profiles for each of the employees (same as standard Profile a User who has an individual role)

So if viewing Jims individual Profile you see Jims info, if viewing Billys Pizza you see the Compamy info, and then list of all of the employees Biily Pizza has also.

Problem I am seeing is i want to be able to access both individual and company profiles from the same url like site/user/jim or site/user/billys-pizza but one Route goes to the Profile where other would be CompanyProfile so I also need to content with user slug being unique accross different tables....

I was thinking User hasMany Profiles and if Individual Role simply don't allow the ability to create a new profile and limit whats available in the form to enter, if a Company how can a Profile have many Profiles....? Stumped

Any thoughts? Ideas? Suggestions? Anything would be greatly appreciated.

Dave

23 May
7 months ago

movepixels left a reply on Middleware Help

I will have to dig deeper. I think the problem is if the JWT middlewar refreshes the JWT then moves onto the Role middleware, the request still has the original JWT so when it tries to find JWT = A and its been expired / blacklisted and is now JWT = B thats why there is no way to get the user->role

movepixels left a reply on Middleware Help

\Log::info($userRole); Logs the role alias as expected, (admin, manager)

The error only appears when the JWT is refreshed and I manually log the user in using the soon to expire JWT

\Auth::onceUsingId($payload['sub']);

It seems when the user is force logged in and moves onto the Role Middleware the auth info is all gone.

movepixels left a reply on Middleware Help

If i run the Role middleware without the JWT it runs fine.

Yes Role <-> User relationship is defined and if I log that is shows the User->Role->alias = manger or admin etc...

movepixels started a new conversation Middleware Help

I have multiple middleware(s) and wondering how does Laravel handle the order of each? Do they run in sequence? All at once?

Route::group(['middleware' => ['cors', 'jwt', 'role:independent,agency', 'access'],

The problem I am running into is jwt middleware will check for valid JWT, refresh if expired and re-log user in like so

\Auth::onceUsingId($payload['sub']); // Log the user using id.

But then I get an error the role middleware "Trying to get property of non-object" on line 21 which looks like this:

$userRole = auth()->user()->role->alias;

Full Role middleware:

public function handle($request, Closure $next, ...$roles)
  {
    $userRole = auth()->user()->role->alias;
    if (auth()->check() && (in_array($userRole, $roles)))
    {
      return $next($request);
    }

    //return redirect('login');
    $response = new Response();
    return response('Unauthorized Role', 403);
  }

Separately each middleware works as expected, but using both when the JWT refreshes and logs the user in to get a new auth->user() in the role middleware it throws that error.

Any ideas anyone?

16 Mar
10 months ago

movepixels left a reply on Get Owner ID In A FormRequest

Sounds good!

Will work on it over the weekend and post result, but for now I thank you all for time and assistance.

Much appreciated,

Dave

movepixels left a reply on Get Owner ID In A FormRequest

Yes this is for admin only which will be me so I will not be doing anything malicious in that degree.

The user backend is using Route model binding, but admin where I am at in development now when it comes to editing actual users records is what I am trying to figure out as best, easy to maintain, and pop into the controllers / models / fors what not

This seems interesting and will check this out.

Route::current()->parameter('parameterName')->owner;

So in my cast would that look like this? Route:

Route::get('/users/{profile}', 'Admin\[email protected]');

And then fetch using:

Route::current()->parameter('profile')->user_id;

Thanks all!

Dave

movepixels left a reply on Get Owner ID In A FormRequest

I was just hoping there was an easier way, but I will just from admin standpoint pull the record direct by id and get all info that way.

Some generic function to convert record id to actual owner should be fine

movepixels started a new conversation Get Owner ID In A FormRequest

What is the fastest, easiest way to get the "user_id" of a record inside a Form Request besides using the Auth

\Auth::user()->id // can not use this way in this case

I am logged in as Admin and if I want to edit any User record the user_id of the record is not me.

What is the bet way to go about this?

Thanks, Dave

14 Mar
10 months ago

movepixels left a reply on Validate Numbered Array

All good. Everything is working now!

Thanks @deansatch for pointing out the name of the field in the data array.

Much appreciated guy! Good looking out....

Dave

movepixels left a reply on Validate Numbered Array

UniqueToUser is a custom Rule class which has been commented out for now to simplify things for the time being.

The foreach works as does :

return [
      'area_id.*' => [
        'required',
        'exists' => [
          'areas' => ['id']
        ]
      ]                   
    ];

Just updating the Laravel sort / save function here since the data array has changed and testing the save.

Will update shortly, thanks guys for the help so far!

Appreciated.

Dave

movepixels left a reply on Validate Numbered Array

Surething.

Where I am at now is trying to make frontend more as if it was coming from laravel. The post array now looks like:

{area_id: 
[108, 110, 86, 100, 268, 137, 91, 90, 106, 88]
}

The FormRequest rules:

public function rules() 
  {
    return [
      'area_id.*' => [
        'required',
        'exists' => [
          'areas' => ['id']
        ]
      ]                   
    ];
  }

Log shows the $input as so:

[2018-03-14 19:11:51] local.INFO: array (
  'area_id' => 
  array (
    0 => 108,
    1 => 110,
    2 => 86,
    3 => 100,
    4 => 268,
    5 => 137,
    6 => 91,
    7 => 90,
    8 => 106,
    9 => 88,
  ),
)  

The SQL error same as before:

Column not found: 1054 Unknown column 'area_id.0' in 'where clause' (SQL: select count(*) as aggregate from `area_profiles` where `area_id`.`0` = 108 and `profile_id` = 79195f1e-b9d9-11e7-80f7-40167eb29fbd)

area_profiles has profile_id, area_id, and timestamps (pivot table)

movepixels left a reply on Validate Numbered Array

OK I changed the post array so it looks like:

area_profiles
:
[{area_id: 110}, {area_id: 108}, {area_id: 86}, {area_id: 100}, {area_id: 268}, {area_id: 137},…]

FormRequest:

return [
      'area_profiles.*.area_id'=> [
        'required',
        'exists' => [
          'areas' => ['id']
        ]
      ]                   
    ];

Still getting the Column not found: 1054 Unknown column 'area_profiles.0.area_id'

movepixels left a reply on Validate Numbered Array

Its a drag / drop sort.

Frontend JS creates the array like so:

this.sorted.push({'id': record.id, 'sort': index + 1, 'area_id': record.area_id})

But now that you mention it I could refactor that to be more inline with what laravel blade would produce.

movepixels started a new conversation Validate Numbered Array

I have seen the other posts about array validation, but my case appears different.

return [
      '*.area_id'=> [
        'required',
        'exists' => [
          'areas' => ['id']
        ], 
        new UniqueToUser($queryModel = 'area_profiles'), 
        new BottomNode($queryModel = '\App\Models\Area')
      ]                   
    ];

as my array looks like:

[{sort: 1, area_id: 137}, {sort: 2, area_id: 86}, {sort: 3, area_id: 108}, {sort: 4, area_id: 268},…]

All the docs I have seen the array validation uses the field dot asterisk 'area_id.*' but for me its *.area_id which produces something like:

Column not found: 1054 Unknown column '0.area_id' in 'where clause' (SQL: select count(*) as aggregate from `area_profiles` where `0`.`area_id` = 268 and `profile_id` = 79195f1e-b9d9-11e7)"

Is there a simple way or am I stuck with a foreach loop?

Thanks, Dave

12 Mar
10 months ago

movepixels left a reply on Laravel 5.5 FormRequest And Custom Rule

Always answer myself too fast!

'area_id'       => ['required', 'exists' => ['areas' => ['id']], new UniqueToUser]

Works as expected!

Thanks guys for the tips!

Dave

movepixels left a reply on Laravel 5.5 FormRequest And Custom Rule

Ok I have it semi-working.

This is good to go so I appreciate the assistance.

'area_id'       => ['required',  new UniqueToUser]

Problem I am hitting is the original syntax using the pipe separator for the exists:areas,id

I tried this but it yelled at me with Method [validateAreas] does not exist.

'area_id'       => ['required', 'exists' => ['areas', 'id'], new UniqueToUser]

Any ideas? That seems to be my last issue, converting the oroginal sytax into this way.

Thanks, Dave

movepixels left a reply on Laravel 5.5 FormRequest And Custom Rule

I have this as of now and I get error

Method [validateRequired|exists] does not exist.

When using this in the FormRequest

use App\Rules\UniqueToUser; // imported in the FormRequest
...

// rule 
public function rules() 
  {
    return [
      'area_id'       => ['required|exists:areas,id', new UniqueToUser]
                          
    ];
  }

Any ideas? I watched the video in the other link and still to no avail, but thanks all the same guys.

Dave

movepixels started a new conversation Laravel 5.5 FormRequest And Custom Rule

Is there a way to use the Custom Validation Rules https://laravel.com/docs/5.5/validation#custom-validation-rules

when using the Form Request?

I do not see it anywhere in the docs, and only similar questions on the web with no answer.

Any ideas anyone?

Thanks Dave

10 Mar
10 months ago

movepixels started a new conversation Error:: Swift_SendmailTransport' Not Found

I just updated to Laravel 5.5 and I am now getting this error.

I have a unique setup where I have one sendMail function and sends from various config files so I can say send from [email protected] or [email protected] and so on.

So I still want to be able to use it as I have it set up so looking for a little help here.

Code looks like:

public function sendMail($data, $view, $subject = 'Default Subject')
  {
    $backup = Mail::getSwiftMailer();
    $account = $data['send_via'];
    
    $host       = Config::get('email.' . $account. '.host');
    $port       = Config::get('email.' . $account. '.port');
    $encryption = Config::get('email.' . $account. '.encryption');

    $transport = (new Swift_SendmailTransport($host, $port, $encryption))
      ->setUsername(Config::get('email.' . $account. '.username'))
      ->setPassword(Config::get('email.' . $account. '.password'));
    $email = new Swift_Mailer($transport);

    Mail::setSwiftMailer($email);
    Mail::alwaysFrom(Config::get('email.' . $account. '.from.address'), Config::get('email.' . $account. '.from.name'));

    $sent = Mail::send($view, ['data' => $data], function($message) use ($data, $subject) {

      $message->to($data->email)
      ->subject($subject)
      ->replyTo('[email protected]')
      ->from('[email protected]', 'dev.com');

      $headers = $message->getHeaders();
    });

    if (!Mail::failures()) {
        return ['success' => true];
      }

  }

Any ideas anyone?

I need to be able to set which email account emails are being sent from so setting only one is of no use.

Thanks, Dave

28 Feb
10 months ago

movepixels left a reply on All FormRequests Missing After Update

Sorry, I corrected that but even with the composer commands I was getting the error.

I started commenting out the methods in the FormRequest to see what was causing the error since Laravel error report needs a degree from MIT to understand and one by one its this little snip that was killing the request / trigger error.

public function all()
  {
    $input = parent::all();
[code]
    return $input;
  }

Not sure why this caused the issue so now to figure that part out.

Thanks for your time and suggestions

Dave

movepixels started a new conversation All FormRequests Missing After Update

I just updated from Laravel 5.4 to 5.5 and all my controllers implement formRequests for all CRUD actions (all working prior to upgrade)

Now every action for store / update result in Class App\Http\Requests\ProfileLanguages\LanguageFormRequest does not exist

There are hundreds of form request files made for this site and they are all where they were in 5.4 and still there now. So I am lost as to what happened?

Snip of original form request as all basically follow this:

namespace App\Http\Requests\ProfileLanguages;

use App\Http\Requests\Request;
use App\Http\Requests\Response;

use App\Models\User;

use Illuminate\Validation\Factory as ValidationFactory;

class FormRequest extends Request

Any ideas? Not even sure where to begin here....

Thanks, Dave