cservices

cservices

Member Since 2 Years Ago

Experience Points 27,380
Experience Level 6

2,620 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 265
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.

15 Mar
5 days ago

cservices left a reply on Auto Model Binding? ? ?

That you all for the info. What you said mixed with watching this video answered a lot for me. https://laracasts.com/lessons/eager-loading

Thanks again, Cy

cservices started a new conversation Auto Model Binding? ? ?

So I have started venturing into Model Binding and really like what I can do with it. But I am seeing something that, for me anyway, seems like it is doing this binding without the need for ->with().

Example: I had some code that looked like this:

$data['this_assets_tags'] = AssetTag::where("asset_id", $id)
            ->with('tag.assetTags.assets')
            ->get();

To access the tag data I would then do something like this in a loop:

@foreach($data['this_assets_tags'] as $tag)
                <div class="asset-view-tag-wrapper">
                    <div class="tag-name">{{ $tag->tag->tagname }}</div>
                </div>
@endforeach

BUT, while making a few changes I ended up changing my code from above to exclude the ->with() method:

$data['this_assets_tags'] = AssetTag::where("asset_id", $id)
            ->get();

Lo and behold, the loop still displayed the tag name within

<div class="tag-name">{{ $tag->tag->tagname }}</div>

I cleared all caches and still it displayed the tagname.

I even did a die and dump on the variable in my class before and after it went to the view. dd($data['this_assets_tags']); and it dod not have the relationship in it.

So is this the way it's supposed to work? Can we actually write a query without the with() method and still have access to the methods within the models - even chained?

I hope this makes sense. And I hope someone can explain this, cause if this is not a bug, then it's a good feature, and good to know there is automatic chaining going on. What I don't get is what is happening to memory when our models have all these relationships built into them, and all that data is being accessed whether you need it or not.

Thanks, Cy

cservices started a new conversation Sorting Relationships

I have a query that looks like this:

            ->with('tag.assetTags.assets')
            ->get();```

Here is what it does: AssetTag (asset_tags) is a pivot table with only two columns. 'asset_id' and 'tag_id'.

First I get all the records for the asset record passed.

Next I get the tag data for each tag related to the asset

I then go back to the asset_tag table to get all the assets belonging to each found tag

Finally I get all the assets for each tag, excluding the asset originally passed

Problem: The page lists the assets that belong to each tag. The boss wants me to prioritize the results by listing the tags according to the amount of assets descending.

Files Related By Tag: Tag: Foo

  • Asset 1
  • Asset 2
  • Asset 3 Tag: Foobar
  • Asset 1

Is there a way to do this without having to break the query apart, writing each relationship individually?

cservices left a reply on Public Storage

This is the only way I can get it to work

file_get_contents(public_path($path_to_stored_file));

cservices started a new conversation Public Storage

I'm in my development environment. I have set the artisan storage:link When I upload a file I do it like this:

$file->storeAs($path, $file_name, 'public');

When I look in finder (Mac) at '/storage/app/public' I see the created directory and all its content.

But, when I look at '/public/storage/' it does not show the same thing.

I cannot seem to access the stored files using storage_path() or public_path(). No matter what I do the end result is that the system can't find the file.

I am creating a DAM (Digital Asset Manager), so I must be able to read these files after saving them to disk so thatI can place content into DB for searching.

Thanks in advance for your help.

05 Mar
2 weeks ago

cservices started a new conversation Saving Created Image

I have an image in my public storage storage/app/public/alkami/backgrounds

I am adding text to the image and creating the image with imagepng($png_image)

Question is, how do I save this image to disc at storage/app/public/alkami

I'm using Laravel 5.4, as my PHP version is 5.something

Here is the full method I am using to create the text over image

public function generateImage()
    {
        //Set the Content Type
        header('Content-type: image/png');

        // Create Image From Existing File
        $png_image = imagecreatefrompng(asset(request()->image_name));

        if (request()->font_color == "#fff") {
            // Allocate A Color For The Text
            $font_color = imagecolorallocate($png_image, 255, 255, 255);
        }

        if (request()->font_color == "#000") {
            // Allocate A Color For The Text
            $font_color = imagecolorallocate($png_image, 0, 0, 0);
        }

        // Set Path to Font File
        $font_path = '/fonts/Arial Bold.ttf';
        $font_path2 = '/fonts/Arial Italic.ttf';

        if (isset(request()->ad_text_one)) {
            // Set Text to Be Printed On Image
            $text = request()->ad_text_one;

            // Print Text On Image
            imagettftext($png_image, request()->ad_text_one_size, 0, request()->ad_text_one_left, request()->ad_text_one_top, $font_color, $font_path, $text);
        }

        if (isset(request()->ad_text_two)) {
            // Set Text to Be Printed On Image
            $text = request()->ad_text_two;

            // Print Text On Image
            imagettftext($png_image, request()->ad_text_two_size, 0, request()->ad_text_two_left,  request()->ad_text_two_top, $font_color, $font_path, $text);
        }

        if (isset(request()->ad_text_three)) {
            // Set Text to Be Printed On Image
            $text = request()->ad_text_three;

            // Print Text On Image
            imagettftext($png_image, request()->ad_text_three_size, 0, request()->ad_text_three_left,  request()->ad_text_three_top, $font_color, $font_path2, $text);
        }

        // Send Image to Browser
        $image = imagepng($png_image);

        // Clear Memory
        imagedestroy($png_image);
    }
02 Mar
2 weeks ago

cservices left a reply on Accessing An Uploaded Public File

Figured out what I was doing wrong.

I was placing the first part of the path in manually /storage/app/public when all I needed to do start with "/storage/" then the path dynamically.

cservices started a new conversation Accessing An Uploaded Public File

I'm having an issue with uploaded files and accessing them.

I have set the storage:link.

When saving a file that has been uploaded do I need to specify public like this? $file->storeAs($path, $machine_file_name, 'public'); $path is a directory.

This saves the file at 'storage/app/public/dirname/filename.

I want to access this file in a couple of ways.

  1. To pass the path to a script - For example: I want to send an uploaded PDF file to a script that will parse it into a string and save that string to a database. I don't want to send the contents, only the path. The script will read the contents.

  2. I want to link to the file for download

Please advise how I can do this.

Thanks, Cy

27 Feb
3 weeks ago

cservices left a reply on First Time Model Binding

Thank you all very much. Very helpful and fun!

cservices left a reply on First Time Model Binding

Great! Thank you!

Now, can I expand that or nest another?

For example: Each extension can have many assets. If I wanted to add the count of how many assets belonged to an extension, and add that data to each extension object, how would I do that?

cservices started a new conversation First Time Model Binding

I'm trying out Model Binding for the first time, and am lost.

Here is what I have.

  1. A table called Types (Model Type)
  2. A table called Extensions (Model Extension)
  3. A Type can have many Extensions

I want to get a list of all Types, but in the same call get all the extensions for each Type object returned.

Make sense.

Thanks in advance. Cy

15 Feb
1 month ago

cservices left a reply on Form Action Dynamically Set

So far the only work-around I have found is to add a script to my @if statement for errors.

<script>
            $("#category_form").attr('action', '/category/update');
 </script>

cservices started a new conversation Form Action Dynamically Set

If there is another way to do this, please advise.

I have a form where the action is set to action="/category/store"

Below the form is a list of items with an edit button next to each. When the edit button is clicked the data is sent to the form and the action is changed to action="/category/update"

The problem is if the form has errors and redirects the action is reset to action="/category/store"

Is there a way to ensure the action retains the update path on a redirect due to failed validation?

14 Feb
1 month ago

cservices left a reply on Axios Access

@WILK_RANDALL - I placed the import line at the top of my js file, which is located at /public/js/dam.js But get this error Uncaught SyntaxError: Unexpected identifier

The import line is the ONLY thing in the JS file at this time

cservices left a reply on Axios Access

@WILK_RANDALL - What file are you placing that in? Can I place it in /public/js/myapp.js ?

cservices started a new conversation Axios Access

I have never used Axios for AJAX and would like to give a whirl.

Every example I see using Axios uses it in conjunction with Vue, but I am not using view.

How do I access Axios for my app.

Is there another way to access it when using public/js rather than /resources/js ?

Thanks, Cy

25 Jan
1 month ago

cservices left a reply on Getting User Info

@MANELGAVALDA - I looked into docs and got my answer based on your help. Thank you!

cservices left a reply on Getting User Info

@MANELGAVALDA - Idid that and got an error: Call to undefined relationship [user] on model [App\Question].

cservices started a new conversation Getting User Info

I have a table ("questions") that contains a user_id to identify which user asked the question.

I want to collect ALL questions, but include some data (name for example) from the User table for each question collected.

Is there a way I can do this Laravel without writing a join query?

21 Jun
8 months ago

cservices left a reply on Trouble Saving Imagick Created File

I was able to get it to work to different ways, and I fixed the extension issue.

file_put_contents( public_path("storage/" . $file_storage_dir) . "/" . $file_name, $imagick);

AND $imagick->writeImage(public_path("storage/" . $file_storage_dir . "/" . $file_name));

The deal with the latter was that I found it written as writeImageFile() on some sites. Using the correct method always helps.

Thanks for all your guidance.

20 Jun
9 months ago

cservices left a reply on Trouble Saving Imagick Created File

I tried that.

                $imagick->resizeImage(200, 200, \Imagick::FILTER_LANCZOS, 1,1);
                $imagick->setImageFormat('jpg');
                $file_name = $filename_minus_ext . "-" . time() . "jpg";
                file_put_contents("public/storage/docs/pdf/" . $file_name, $imagick);

I just get an error message file_put_contents(public/storage/docs/pdf/phparchitect-2017-11-1529522507jpg): failed to open stream: No such file or directory

cservices started a new conversation Trouble Saving Imagick Created File

I am using Imagick to create a thumbnail image of a PDF page.

I’m getting everything to work, except I can’t figure out how to save the image.

$file['temp_path'] is the temp location of the PDF file that is being uploaded. I’m telling Imagick to use that version of the file to create the thumbnail image.

From there I’m going to a best fit of 200 x 200, and creating the image as a jpeg.

The raw image is kept in $imagick->getImageBlob() (I think), but I don’t know how to store this to my storage location.

The storage location depends on the type of file being downloaded. In this case “storage/app/public/docs/pdf”.

Can someone please show me the best way to save the thumbnails to the storage location, according to Laravel?

Thanks.

$imagick = new \Imagick($file['temp_path']);
$imagick->resizeImage(200, 200, \Imagick::FILTER_LANCZOS, 1,1);
$imagick->setImageFormat('jpg');
$file_name = $filename_minus_ext . "-" . time() . "jpg";
14 Dec
1 year ago

cservices left a reply on Complex DB Query

Mine is kinda similar. I decided to go with

Project::where ('cat_id', '=', 1)
            ->whereBetween('start_ts', [$start_month, $end_month])
            ->orWhereBetween('end_ts', [$start_month, $end_month])
            ->get();

Of course I now I realize that I was completely over-thinking this. The other project was even more complex than this. In this case, as long as a recorded entry does not contain a start or end date within the range of the new record, then the new guy can come on in. :D

Thanks for the responses and giving me stuff to think about more clearly.

cservices left a reply on Complex DB Query

The purpose of the query is to find any record of a said category that already exists within the date range the user selected.

If a user puts in the dates of 2/2/18 - 5/15/18 and it records that record successfully, then the months of February, March, April, and May are taken and cannot exist in any other entry for that category.

So if the user tried to place any date in another entry that contained any one of those months, they would be alerted that the months are already taken by another record. There cannot be any overlap.

The start_ts is saved as mm/1/yyyy 00:00:00. The end_ts is saved as mm/last-day-of-month/yyyy 23:59:59.

If anyone knows of another way to do the exact same thing I am certainly open to it. Working with date/time is not my strong point. :)

cservices started a new conversation Complex DB Query

I had to write a complex query for a project long ago. At the time it was written using Drupal. I'm trying to figure out how to write this in Laravel.

I have resorted to writing it using DB::raw(), but would really like to know how to write it using Laravel. It's go so much that I get lost when trying to group parameters.

Can someone show me how the following would be written in Laravel?

Thanks in advance for your time and your help.

''' $raw_sql = "SELECT * FROM projects WHERE ( ( (start_ts <= $start_month) OR (start_ts BETWEEN $start_month AND $end_month) ) AND ( (end_ts BETWEEN $start_month AND $end_month) OR (end_ts > $end_month) ) ) AND (cat_id = 1)";

     $query = DB::select(DB::raw($raw_sql));

'''

20 Oct
1 year ago

cservices left a reply on Adding And Populating A Field To The Users Table

Thank you ftrillo for that. Makes great sense, and I will remember that for later use.

After some searching through the adldap2-laravel docs I found something that prompted me to test and I am glad to say works very well in my case.

The following only applies to adldap2-laravel, which can be found at https://github.com/Adldap2/Adldap2-Laravel/blob/master/docs/auth/fallback.md#developing-locally-without-an-ad-connection

adldap2-laravel can sync your local database with any data you throw at it within the config/adldap_auth.php

At the bottom of the config, under Sync Attributes, I had originally placed

'sync_attributes' => [
        'username' => 'samaccountname',
        'name' => 'cn',
    ],

The data coming back from the server had included the email address, so I could add it to the table simply by making the following change.

'sync_attributes' => [
        'username' => 'samaccountname',
        'name' => 'cn',
        'mail' => 'mail',
    ],

After this I had to add the “mail” field to by users table. From there I login to my app again, and the field is then populated with the Active Directory email value. Now I have access.

I hope this helps others who use Adldap2-Laravel.

Thanks, Cy

cservices started a new conversation Adding And Populating A Field To The Users Table

I’m a beginner with Laravel, but have been coding PHP for many years. Presently I have a project where I am using “adldap2-laravel” to connect to our Active Directory. The email address is not used for the user login, so I had to make changes per the “adldap2” instructions for using “username”. However, there are times in the app where I need to use some user information that is not part of “Auth::user()”. In this case, the user’s email address.

I need a way to access the user’s email address for use within some of my methods. Otherwise I have to build it within a method, like this. Auth::user()->email = Auth::user()->username . "@mydomain.net"; Or $ useremail = Auth::user()->username . "@mydomain.net";

This is not ideal, as it is not retained in the Auth::user() since it was created in the method.

So I could do this one of two ways. Both in which I need some guidance.

  1. Create a new field in the users table to hold the “useremail” address, which would also be created using code to concatenate username with “@mydomain.net”.

  2. Do the concatenation mention above in some sort of boot or login file.

Ideally, both of these would have the end result as part of the Auth::user() for ease of access any time. BTW, I am using Laravel version 5.4

Suggestions with instructions would be very much appreciated.

Thanks, Cy

06 Apr
1 year ago

cservices started a new conversation Login Via Active Directory And Limited Access

I am using Adldap2 to connect to our Active Directory. I have never done anything like this before, and still getting used to Laravel.

In a previous app I had created a gate: Gate::define('superadmin', function ($user) { return $user->superadmin == 1; });

This worked very well for me.

If I am to understand Adldap2 correctly, and having yet to connect to the Active Directory, when an attempt to login is successful, it will write the user to the 'users' table in the app.

But how do I limit the access to only certain users? Especially since I am not allowed to edit or make changes to the Active Directory.

There are hundreds of people in the Active Directory, but only a handful are to have access to the backend of the app. Can the users be assigned to the 'users' table before they try to use the login via the Active Directory? If not, can I have a field in the table (like “superadmin”) that defaults to null, then manually edit the table and change the value to 1 and have a gate similar as above?

Thanks in advance for your help.

16 Mar
2 years ago

cservices left a reply on Broadcasting Without Redis & Echo

I have been trying to test. I just don't know what is wrong or how to get it to communicate across socket. Here is code info if it can help you help me.

/// CLASS - SomeEvent

15 Mar
2 years ago

cservices started a new conversation Broadcasting Without Redis & Echo

Let me explain what I am trying to do:

I built a dashboard for our Marketing dept. A very simple display of a few of marketing’s happenings. One section is a message board. It is not interactive. It only displays messages entered into the admin, and people can click to read them.

In attempting to learn Broadcasting, I thought it would be nice to update the div containing the messages by prepending new messages to the list, and possibly create an alert of some sort for items updated. All for people who have the dashboard opened if an admin adds/updates a message.

In my looking into socket.io, it appears to me that I don't need the overhead of Redis, and I want to use JQuery, rather than Echo, if at all possible.

The question is, how?

I have played with Events, and I get how they work, but I don't understand anything beyond that when it comes to sending to a socket and so on. I could really use some guidance. The documentation and tutorials I find all use Echo and Redis or Vue and such. But what about if you are not using any of those.

Thanks in advance for your help. Cy

PS: I have zero experience with socket.io. Have been watching some videos that make it look simple, but nothing in the way I want to use it.

14 Mar
2 years ago

cservices left a reply on Broadcasting 1,2,3

Thanks for the response. Much appreciated.

cservices left a reply on Broadcasting 1,2,3

The only problem is that it uses Pusher, and I cannot use a third-party.

I need direction on how to this with Redis, Echo and socket.io. And the only reason I know I need those is because someone in the IRC chat told me so. For all I know that is wrong.

cservices started a new conversation Broadcasting 1,2,3

It’s so frustrating to search for answers on broadcasting, and find that between documentation and other sites that might write things like a tutorial, there is nothing that goes step by step, with an attitude of teaching people as if they just don’t know what is going on.

Broadcasting in Laravel 5.3 looks really cool, and I want to learn it

My company does not want servers communicating outside the network any more than they have to. This means third party is out of the question.

The Laravel 5.3 documentation leaves me with more questions than answers.

Install Redis, Node, Socket.io and Echo. For all I know there is probably four or five other things I need to install. In other words, other than feeling somewhat comfortable with events/listeners, I have no idea how to get this off the ground.

Is there any instruction out there that will show me how to do this step by step? Something that approaches teaching a novice?

I’m not a novice when it comes to PHP, but I am when it comes to Laravel.

Please don’t point me to the docs. I’ve all but seared them to my brain.

Thanks, Cy