cservices

cservices

Member Since 2 Years Ago

Experience Points
33,510
Total
Experience

1,490 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
315
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 7
33,510 XP
Aug
14
2 months ago
Activity icon

Replied to Finding Records That Have A Date Range, Using A Single Date

I may not have worded that correctly.

The record has to dates, start/end, and the query has only one. It needs to match one of those, or be between them.

Activity icon

Replied to Finding Records That Have A Date Range, Using A Single Date

I started with pretty much exactly as you suggesed, but I did not get the results I should have. Later I found that I needed to do the reverse with the where clause, so this is what I did:

$data['player_plays'] = PlayerPlay::where([
  ['play_date_start', '<=', $draw_date],
  ['play_date_end', '>=', $draw_date],
  ['game_id', '=', $game_id]
  ])->with('plays')
  ->get();

Once I did that everything came together.

Thanks for your input.

Activity icon

Started a new Conversation Finding Records That Have A Date Range, Using A Single Date

I have a database with two fields that are dates. A start field. A end field.

If the date I am using to search is 2019-8-10, what would the query look like in Laravel to find all records whose start and end are either on, or between this date?

Thanks in advance for your help.

Jul
24
3 months ago
Activity icon

Replied to Gate Not Working Correctly

In the LoginController __construct() I commented out

    {
        //$this->middleware('guest')->except('logout');
    }

And now it appears to work. Still don't understand the reason though.

Activity icon

Started a new Conversation Gate Not Working Correctly

Laravel 5.4 question - Note: all of this is internal access. No one can access this from outside, so the code shown does not pose a risk.

I have an app where I use a gate to determine allowed access. It is very possible that a user exists in the database, but does not have an allowable value. Here is the gate:

Gate::define('has_access', function ($user) {
            switch($user->access) {
                case 'access':
                case 'admin':
                case 'superadmin':
                    return true;
                    break;

                default:
                    return false;
            }
        });

Here is the gate in the controller

if (!Gate::allows('has_access')) {
            return redirect('/login');
 }

But if a user that is OR is not in the database AND does not have a value that allows the login, the user, according to the browser address bar, is still sent to /home, but the page is a white page stating:

This page isn’t working member-profile-tool redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

I am using "adldap2/adldap2-laravel": "^3.0", so when a user not intentionally added to the app database attempts entry, they are added to the database with a default value in the "access" column that would deny access.

The ONLY time the gate appears to work is if the user has a value that that allows them access, but are not yet logged in. Otherwise it gives me the page mentioned above.

I hope this makes sense. Any help would be appreciated.

What I want to ensure is that users not given access are sent back to the login page, and given a flash that they are denied.

Thanks in advance, Cy

Jul
22
3 months ago
Activity icon

Replied to Saving Errors To DB / Custom Error Messages

Thanks for the info. You direction led me to more understanding of how logs work in Laravel. I found that I could actually split the logs to daily, and how I can add my own text to them.

Jul
17
3 months ago
Activity icon

Started a new Conversation Saving Errors To DB / Custom Error Messages

Im using Laravel 5.4. In my app I want to log to the database error messages created by specific methods. I also want to display a custom message to the user and refer them back to a specific page once they acknowledge the error.

Are there any tutorials out there to help explain how I might do this? Any thoughts or advice on the direction to go?

Some people in chat suggested some third-party stuff, but that is not an option where I work. It all has to be done internally.

Thanks in advance for your help.

Jun
21
4 months ago
Activity icon

Replied to Saving A New Image

I looked into Intervention and it's actually pretty good for what I need. Simplified things tremendously.

Thanks for your help. I will still be looking into things you folks have pointed out. I still want to know how to do it the long way.!

Activity icon

Started a new Conversation Saving A New Image

I am creating a thumbnail image and am lookin to store it publicly.

Ultimately the path would be created in /storage/public/profiles/record ID/thumbnail_record id.jpg

I tried creating this with public_path() like this:

        $path_to_file = 'storage/public/profiles/'.$profile_id;
        $storage_path = public_path($path_to_file . "/thumbnail_$profile_id.jpg");

But I get an error: imagejpeg(/Users/cyj/websites/htdocs/member-profile-tool/public/storage/public/profiles/51/thumbnail_51.jpg): failed to open stream: No such file or directory

What is the best way to save a resized image that I need to access publicly?

BTW - I know there is a package called "intervention" but I'm not using it.

Thanks

Jun
18
4 months ago
Activity icon

Started a new Conversation Custom Validation Message

I would like top create a more custom validation message. I do not need to rewrite or create a custom validation rule, just the message.

Any way to do this?

Thanks in advance.

EDIT: Sorry, I should have specified Laravel 5.4

Activity icon

Replied to Validating Dynamic Fields Using Array Naming Convention

I realized I was over complicating things with my use of array fields names. Since I was generating a unique name for each, there really was no need to name them that way. Changing this allowed the validation to work.

Thanks for your help.

Jun
17
4 months ago
Activity icon

Replied to Validating Dynamic Fields Using Array Naming Convention

@TRAY2 - Using your example I built the code to create the validation array. However, no matter how I do it, when any of the dynamic fields are present, it says it has no value, when I know it does.

To explain what the first part of this code is doing... I have a hidden field that keeps track of the index numbers. So, for example, it might have the values of "1,3,4"

The code turns this into an array in the controller method, to be used in the foreach to generate the field names for the validation to work.

Here is my validation code:

$form_channel_fields = array(); // Holds dynamic fields names
            if (isset(request()->profile_form_channel_ids)) {
                // Creates an array of index numbers
                $channels_field_nums = explode(",", request()->profile_form_channel_ids);

                // Creates individual array elements in key/value pairs
                foreach($channels_field_nums as $channel_num) {
                    $form_channel_fields["channel[$channel_num]['channel']"] = 'required';
                    $form_channel_fields["channel[$channel_num]['pub_date']"] = 'required_if:channel['.$channel_num.']["status"],==,4';
                }
            }

            // Typical Laravel associative array with validation codes
            $other_validated_fields = array(
                'first_name' => 'required',
                'last_name' => 'required',
                'job_title' => 'required',
                'classification' => 'required|not_in:none'
            );

            // Merge $form_channel_fields and $other_validated_fields into $collected_validation_fields
            $collected_validation_fields = array_merge($form_channel_fields, $other_validated_fields);

            // Validate fields
            $this->validate(request(), $collected_validation_fields);

In case you are wondering, here is a dd() of the $collected_validation_fields array using my index example of "1,3,4":

array:10 [▼
  "channel[1]['channel']" => "required"
  "channel[1]['pub_date']" => "required_if:channel[1]["status"],==,4"
  "channel[3]['channel']" => "required"
  "channel[3]['pub_date']" => "required_if:channel[3]["status"],==,4"
  "channel[4]['channel']" => "required"
  "channel[4]['pub_date']" => "required_if:channel[4]["status"],==,4"
  "first_name" => "required"
  "last_name" => "required"
  "job_title" => "required"
  "classification" => "required|not_in:none"
]

I keep the dynamic fields separate from the non-dynamic for my own sanity. I then merge them into one and feed it to the validation method. It works for the non-dynamic fields, but it does not appear to notice the dynamic field values. This is my error message:

The channel[1]['channel'] field is required.
The channel[3]['channel'] field is required.
The channel[4]['channel'] field is required.
The first name field is required.
The last name field is required.
The job title field is required.
The selected classification is invalid.

Thanks in advance for any help you can offer.

Activity icon

Started a new Conversation Validating Dynamic Fields Using Array Naming Convention

I have a form where one section creates a new set of fields dynamically. So if one set of fields were created, the markup for the fields may look like this. Notice the naming convention for the "name" property in each.

<select class="custom-select profile_form_channel_selector" data-web_page_selector="web_page_selector_1" name="channel[1]['channel']">
    <option value="">Select a channel</option>
    <option value="1">Unassigned</option>
    <option value="2">Web Page</option>
</select>

<select class="custom-select" name="channel[1]['status']">
    <option value="3">Pending</option>
    <option value="4">Published</option>
    <option value="1" selected="">Unassigned</option>
</select>

<input type="text" class="form-control publication_date hasDatepicker" id="publication_date_1" name="channel[1]['pub_date']">

So if a set of these fields exists, the first validation would make sure that the "channel[1]['channel']" has a value.

Next, if the "channel[1]['status']" has a value of "4" (Published), then the "channel[1]['pub_date']" must have a value.

I'm not understanding how this would be coded in the validation area (Laravel 5.4). An example would be appreciated.

Thanks in advance

Activity icon

Replied to Making Better Forms And Use Of Laravel

@SNAPEY - Have not made use of "old" very much, but figured I needed to with the validation. I did not know/remember about the second argument that can be added.

Thank you for your input.

Activity icon

Replied to Making Better Forms And Use Of Laravel

@LOUDRIOT - Thank you for that.

No, I am not placing PHP for handling the form in the blade.

Activity icon

Started a new Conversation Making Better Forms And Use Of Laravel

I'm a lone developer who is self taught. I have only places like this to ask questions and get answers. I'e been developing in PHP for years, and using Laravel for about the last three to four years.

My question is about building forms. Most of my work is on the backend, and I create all the interface for it as well as the processing code. But my blades that contain form code, mixed with template and PHP code, seems to get pretty crowded with the code I have to add to populate selects areas, radio/checkboxes and such.

Can you tell me the best method, or point to a tutorial, to create a form that is is not only used to store data, but to edit it as well? In addition, how to re-populate if the form validation fails?

Ive done this sort of thing many times before, but because the blades seem to get so crowded, I question if I am doing it correctly. - I am not using Vue or anything like it.

Thanks in advance for your advice.