movepixels

movepixels

Member Since 1 Year Ago

Experience Points 3,690
Experience Level 1

1,310 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 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.

25 Jun
1 day ago

movepixels left a reply on Validation Required_unless Not Working

Ok not ideal but solved by setting the checkbox false value to null so this validation works now:

'left' => 'required_without:right',
 'right' => 'required_without:left',

Will use this for now.

movepixels left a reply on Validation Required_unless Not Working

Validation is still failing though.

Inside rules() i have:

\Log::info('INPUT');
\Log::info($input);

\Log::info('RULES');
\Log::info($rules);

Which shows:

[2019-06-25 15:24:30] local.INFO: INPUT  
[2019-06-25 15:24:30] local.INFO: array (
  'left' => 0,
  'right' => 0
)  
[2019-06-25 15:24:30] local.INFO: RULES  
[2019-06-25 15:24:30] local.INFO: array (
  'left' => 'required_unless:right,1',
  'right' => 'required_unless:left,1',
)  

But it is still failing to catch the rules.

movepixels left a reply on Validation Required_unless Not Working

Ok solved. Not sure what happened, reverted to half hour back version and all is good. Not sure why but its working.

Thanks for your time all the same :)

Dave

movepixels left a reply on Validation Required_unless Not Working

I dont know whats going on. All of a sudden every formRequest is not getting called. And I have hundred or so and I sure know I did not edit every one of of them in the last half hour to break them all!

Always something.

movepixels started a new conversation Validation Required_unless Not Working

I have in a formRequest:

'left' => 'required_unless:left,1',
'right' => 'required_unless:right,1',

So basically what I want is to make each field required if the other is not selected. either left, or right is selected or both.

But the form is passing validation with neither selected.

Verified that the Request payload is sending those fields and they are:

{right: 0, left: 0}

But still validation fails.

Any ideas?

Thanks,

Dave

24 Jun
2 days ago

movepixels left a reply on Laravel Resource Help

Solved it like so:

$records = $this->collection->get('records');
$selectables = $this->collection->get('selectables');

But is that the most ideal way?

movepixels started a new conversation Laravel Resource Help

I am trying to pass an array of info to the resource, but it did not like the array so I used collection to pass it.

$response = [
      'records' => $profile->language,
      'selectables' => $selectables
 ];

$collection = collect($response);
return new LanguagesCollection($collection); // collecton of records

But how do I access the individual records and selectables from inside the LanguagesCollection resource?

I tried to no success:

$this->collection->records;
$this->collection['records'];
$this->records;

If I do a simple return just to see the info has made it inside the resource:

public function toArray($request) {
     return $this->collection;
}

I get this in the browser response:

{
     records: [array all my records data],
     selectables[array all my records data]
}

Any ideas?

Thanks,

Dave

23 Jun
3 days ago

movepixels started a new conversation Remove Response Header

Just curious on how to remove

www-authenticate: jwt-auth

from Laravel response headers?

This is what I get back:

Cache-Control: no-cache, private
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Date: Sun, 23 Jun 2019 16:27:00 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.27 (Win64) OpenSSL/1.1.0f PHP/7.1.9
Transfer-Encoding: chunked
www-authenticate: jwt-auth
X-Powered-By: PHP/7.1.9
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 58

Thanks,

Dave

21 Jun
5 days ago

movepixels left a reply on Array Not Returning Correct

Thanks for the response. What I was doing was create an array of days where the key represented the day numerically (0-6).

So my array was 3 => {data for Wednesday}, 5 => {data for Friday } and so on.

I just revered the array in Laravel so it gets keyed as Friday => {data for Friday } and on the front end converted the key back to a 0-6 dayOfWeek week value using $moment. Not ideal and kind of a pain in the ... but it works now.

I am using the Laravel Resource for API response so I guess the public function toArray($request)will sort it?

But oddly in the same Resource this $this->collection->groupBy('day', 'asc') remains as it should.

I might give your idea a try.

movepixels started a new conversation Array Not Returning Correct

I am building an array and using a key => value as the key and it should be working but its displayed with keys 0,1,2 and not how I'm setting them.

public function getNewUsed($records) {

    $used = [];

    foreach($records as $k => $v){

      $key = $v['day'];

      if(array_key_exists($key, $used)) {
        array_push($used[$key],range($v['start'],$v['end']));
      } else {
        $used[$key] = []; 
        array_push($used[$key],range($v['start'],$v['end']));
      }
    }

    \Log::info('USED BELOW');
    \Log::info($used);

    return $used;
}
~~~

I log the array and the log shows the correct array as :

[2019-06-21 17:32:56] local.INFO: array ( 2 => array ( 0 => array ( 0 => 0, 1 => 1, 2 => 2, ), ), 4 => array ( 0 => array ( 0 => 8, 1 => 9, 2 => 10, ), ), )


But when added / returned to the controller response it is keyed like: 0 and 1 when for the sake of this example it should be keys 2 and 4

array ( 0 => array ( 0 => array ( 0 => 0, 1 => 1, 2 => 2, ), ), 1 => array ( 0 => array ( 0 => 8, 1 => 9, 2 => 10, ), ), )


Any ideas? Seems quite odd.

Thanks,

Dave

movepixels left a reply on Exception Handling

Thanks for the response. Just wondering why with the code example I provided why the catch is being ignored\ when coded in the controller?

public function destroy(Profile $profile, Schedule $schedule)
  {
      try {
        $record = $profile->schedule()->findOrFail('456')->delete(); // coded to fail
      } catch(\ModelNotFoundException $e) {
        return response()->json(['message' => 'model not found exec'], 404); 
      } catch (Exception $e) { // Anything that went wrong
        return response()->json(['message' => $e->getMessage()], 500); 
      }
    $response = $this->getSchedule($profile);
    return response()->json($response);
  }

It calls the ModelNotFoundException () without me having to put in throw new ModelNotFoundException ();

20 Jun
6 days ago

movepixels started a new conversation Exception Handling

I have a destroy function as an example like this:

public function destroy(Profile $profile, Schedule $schedule)
  {
      try {
        $record = $profile->schedule()->findOrFail('456')->delete(); // coded to fail
      } catch(\ModelNotFoundException $e) {
        return response()->json(['message' => 'model not found exec'], 404); 
      } catch (Exception $ex) { // Anything that went wrong
        return response()->json(['message' => $e->getMessage()], 500); 
      }
    $response = $this->getSchedule($profile);
    return response()->json($response);
  }

Now none of the catch exceptions are being called. The app/Exceptions/Handler.php seems to take over.

public function render($request, Exception $e)
    {
        if ($e instanceof ModelNotFoundException) {

            return response()->json([
                'message' => 'Request could not be completed.'], 404);
        }

        if ($e instanceof Exception) {
            return response()->json([
                'message' => 'Looks like we need to fire someone since something is broken our end. We are aware of the situation and in the process of fixing the isse.'], 500);
        }
    }

Am I going about this wrong? Do I need to even bother with the catch in the destroy function? Or how can I force the catch in it?

The handler sends the response direct to the front-end (Laravel is acting only as an API backend). This is fine if it sends direct to frontend, but just want to know if I am going about this right or where I am going wrong.

I can write the destroy like:

public function destroy(Profile $profile, Schedule $schedule)
  {
    $record = $profile->schedule()->findOrFail('456')->delete(); // coded to fail
    $response = $this->getSchedule($profile);
    return response()->json($response);
  }

And both end up with the same result with handler sending the 404 Request could not be completed. message.

Thanks,

Dave

12 Jun
2 weeks ago

movepixels left a reply on Combine Arrays

Solved using Collections

$collection = collect([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);

movepixels started a new conversation Combine Arrays

This seems so simple, but I have tried array_merge, array_push and it always overwrites the original array values. Basically I am looping thru an array and trying to combine them.

Array(3)
0: (2) [9, 10]
1: (8) [35, 36, 37, 38, 39, 40, 41, 42]
2: (4) [44, 45, 46, 47]

I need to end up with Array(1) 0: (14) [9, 10, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47]

Thanks,

Dave

29 May
4 weeks ago

movepixels left a reply on Help With Functions

i did the import:

import { set } from '@/utils/vuex-reusable-functions'

And inside an action:

async GET_RECORDS({ commit }, url) {
    commit('setLoading', true)
    try {
      const response = await this.$axios.$get(url)
      setUser: set('user')
      commit('setUser', { name: 'foo' }) // as a test
      return response
    } catch (e) {
      return Promise.reject(e)
    } finally {
      commit('setLoading', false)
    }
  },

Results in error , no-labels, it does not like the setUser: set('user') line

28 May
4 weeks ago

movepixels left a reply on Help With Functions

Yes I know about Vuex, thats what I am using. But I came across these "re-usable functions".

I just cant seem to figure out how you use these functions.

movepixels started a new conversation Help With Functions

I came across this snip and wondering how to actually use it?

https://gist.github.com/rhythnic/6521495650a215ccab8bf7120949fb7d

I tried just the simple example of set but I get errors. Unexpected labeled statement no-labels

In the store I tried:

setUser: set('user')
commit('setUser', { name: 'foo' })

Any ideas how to use these functions?

Thanks,

Dave

09 May
1 month ago

movepixels left a reply on Modify Data After Query Before Sending To Front-end

No worries. But as stated the actual users dob can never hit the front end. So "doing some calculations in the front end" to the request / response means anyone with dev tools can simply inspect the response and see the format 1977-04-23 which is not allowed. It can never be revealed the users actual dob hence the question to modify it BEFORE being sent to front end!

Consider this closed anyways.

Thanks all for time and input.

movepixels left a reply on Modify Data After Query Before Sending To Front-end

Ohh my, nevermind guys.

I DO NOT HAVE ACCESS TO HOW THE DATA IN THE ARRAY IS FETCHED FROM THE DATABASE! I am getting the data as a result of an API call to a 3rd party. I get the data how they send it. I do not have ability to modify how the data that is provided to me. I make an API call to a server that I DO NOT CONTROL HOW THE QUERY IS FETCHED FROM THEIR DATABASE they simply send back the data array with dob => YYYY-MM-DD format and I then must change it before sending it to OUR front end.

For those who might find a simple term easier to follow I order a burger from McDonalds => it arrives with onions => i hate onions so i remove them (alter the result) => I do not walk back into the restaurant and make my own burger.

I figured it out all the same. Wasted more time explaining it than actual time to code it!

08 May
1 month ago

movepixels left a reply on Modify Data After Query Before Sending To Front-end

The data / array is passed to the front-end as a JSON response (no blade templating, laravel is API only, no views) So the data that hits the front end in this example dob can not be ever passed as the users actual data, only the dob converted into the age value can be sent in the data so the modification takes place on the server, prior to being sent back via the request.

I / me get the array data only. For the sake of the question any SQL db results or altering the query or table / fields are not an option. I have / get the the result of the query and my job is to modify what I have been given in the data array into what I need it to be then passed to the front end. I do not have the option of how the data is retrieved from the database. I simply get the array data as a middle / in between phase of the request / response.

movepixels left a reply on Modify Data After Query Before Sending To Front-end

That function simply takes 1 value and converts it into years, that I know how that's simple.

Yes I can simply loop for each and replace the dob value with Carbon::createFromFormat('Y-m-d', $users[$k]['dob'])->year which I said. But there has to be a BETTER way than simply looping thru a for $k as $v thats what I am asking. Not how to change 1 value in 1 spot. Hundreds of dob in the huge array in a way that is efficient. Looping for each is not the most practical way so thanks for your time but clearly do not understand the question.

movepixels left a reply on Modify Data After Query Before Sending To Front-end

No no, the original array but change the value of key dob => 1977-04-23, i need to send the dob => 42. The entire array all the data still goes to the front end, as is un-changed. I simply did not include 100 keys in the question

$users = Array
(
    (0) => Array
        (
            ..... 50 other keys
            (dob) => '1977-04-25', // only changing this into years, rest stays the same and goes to front end
            ...... 50 more keys
        ),

    (1) => Array
        (
            ..... 50 other keys
            (dob) => '1972-09-06', // only changing this into years, rest stays the same and goes to front end
            ...... 50 more keys
        ),

    (2) => Array
        (
           ..... 50 other keys
            (dob) => '1985-11-20', // only changing this into years, rest stays the same and goes to front end
            ...... 50 more keys
        )
);

movepixels left a reply on Modify Data After Query Before Sending To Front-end

The array has ~100 key /values and the entire object can have 1000 entries so thats a lot of looping. Was looking for an actual php array function / combination of that would reduce the overhead. I need all the values from the array so pulling the ages out and sending as a separate array makes no sense to me.

movepixels started a new conversation Modify Data After Query Before Sending To Front-end

I have an array of results that looks / similar like this:

$users = Array
(
    (0) => Array
        (
            (dob) => '1977-04-25',
            ......
        ),

    (1) => Array
        (
            (dob) => '1972-09-06',
            ......
        ),

    (2) => Array
        (
           (dob) => '1985-11-20',
            ......
        )
);

And what I need to do is find / replace the dob values with a Carbon function to return age. I do not want the actual data / dob to reach the front end so I need to alter it after the results but before the front end receives it. I know the key will be "dob" but can't figure out the correct way to loop thru the array properly and use a function to replace dob value with something like Carbon::createFromFormat('Y-m-d', $users[$k]['dob'])->year For the site privacy policy DOB can not be accessable so I need to restrict the value to an age only value (25 years old) So array_walk function with array_search but not having any luck.

Any ideas / insight would be appreciated.

Thanks,

Dave

28 Jan
4 months ago

movepixels started a new conversation Complicated Query Help

I will try to explain in detail as this is quite difficult. A User can belong to many Area so I have a pivot for that area_user pivot I have a pivot of user_upgrade (user_id, upgrade_id, area_id, expires) An upgrade has a set duration, keep it simple say 7 days hence the expires in the user_upgrade pivot table. And each area is only allowed a specific number of "upgrades" per week.

What I need is in English get all available upgrade (upgrade_id) for the next 2 weeks that have not gone over the allowed upgrades for that area.

This gets me 1 specific count for an upgrade:

// GET THE NUMBER OF UPGRADES CURRENTLY USED
    $used = DB::table('profile_upgrade')->where('upgrade_id', 1)->where('area_id', $area_id)->whereDate('end_date', $expiration)->count();

But if user has 5 areas, and there are 4 possible upgrades for the next 4 weeks looping thru this will be 5 queries * 4 possible upgrades * 4 weeks is a hell of a lot of queries.

And ultimately I only want maximum of 4 results returning the first available upgrade within the next for weeks. So if all spots for area 10 in week 1 for upgrade 1 are filled exclude it and move onto week 2, if available stop since we only need 1 record per upgrade, move onto finding what available for upgrade 2.

Idealy the query result would be like:

0 => [
    upgrade_id => 1,
    week => 2,
    area_id => 25
],
1 => [
    upgrade_id => 2,
    week => 4,
    area_id => 17
],
2 => [
    upgrade_id => 3,
    week => 1,
    area_id => 2
],
3 => [
    upgrade_id => 4,
    week => 6,
    area_id => 11
],

I know this is quite an ask but any insight / ideas / suggestions would be much appreciated.

Dave

27 Jan
4 months ago

movepixels left a reply on Help With TimeZones

https://laracasts.com/@shaikh709

Package looks great, simple and should do exactly what I was looking for.

Thanks!

26 Jan
5 months ago

movepixels left a reply on Help With TimeZones

Needs to be based on the users zone, so it needs to be dynamic. User in NY posts a comment at noon, cant display in California Posted today 12:00pm when its only 7:30am in the morning there.

movepixels started a new conversation Help With TimeZones

I have the server / laravel set to UTC time zone. Problem I am having is during validation I have a rule as below:

$rules['start_date'] = 'required|date|after:yesterday|after_or_equal:today';

Problem is I am -3.5 hours behind UTC so it might be a new day according to UTC time but for me it is still the same day.

Example today when I am currently writing this it is 9:10pm Jan 26 here, but 12:40 am Jan 27th UTC so when I try to save this form its failing.

How can I properly handle this situation?

Thanks,

Dave

11 Jan
5 months 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
5 months 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
7 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
7 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
7 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
7 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
7 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
7 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
8 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
8 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
8 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
8 months ago

movepixels left a reply on Distinct Query

I went with ->unique collection.

Works as needed :)

Thanks.