saadaan

saadaan

Member Since 3 Years Ago

Experience Points
5,620
Total
Experience

4,380 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
9
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 2
5,620 XP
Oct
22
1 week ago
Activity icon

Started a new Conversation Detecting If An Image Is Uploaded

Hi,

I am trying to detect in the controller if the variable carrying the image upload has some content in it or not (means image is uploaded or not), so that I could trigger image saving code. Can someone mention how to do it? Is this code right? user_photo is the actual variable which should have the image coming from the blade, if image is selected in UPLOAD FILE dialogue.

                if($request->user_photo)
                {
			... #image saving code
                }

Let me know if there is a better way.

Thanks, Saad

Oct
19
1 week ago
Activity icon

Replied to Using Yajra Datatables - Running Out Of Memory

Thanks. I am wondering that isn't this the sole purpose of yajra plugin, since it is server-side processing? If the plugin does paginate AND on the server, it should send me only first 25 set of results, no?

Oct
18
1 week ago
Activity icon

Started a new Conversation Using Yajra Datatables - Running Out Of Memory

Hi,

I am trying to use Yajra's datatable plugin for a large dataset (>100K rows). It works fine when table entries are less than 10k. But when entries are > 50k, Laravel/PHP starts throwing following error:

PHP Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 12288 bytes)

I have tried using memory_limit = -1, but still it does not work properly. It does not throw error now, but doesn't even load the table as well. The server is fairly powerful (16G RAM) and does not run out of memory during loading.

Any solution to this? I am using Apache HTTP server. I thought yajra plugin was suitably design to solve the exact same problem, but I am still stuck with how to display a big dataset.

Thanks, Saad

Oct
17
2 weeks ago
Activity icon

Replied to Action Button In Laravel Yajra

Much thanks!

Activity icon

Replied to Action Button In Laravel Yajra

I have tried this already. The datatables throws an error on blade page, saying "UNDEFINED VARIABLE: FORM"

Activity icon

Started a new Conversation Action Button In Laravel Yajra

Hi,

I am trying to use action buttons in laravel yajra, but needing some help. Following is the old syntax I used in blade syntax:

<td align="center"><a href="viewformdetails/{{$form->id}}"><button class="btn btn-success btn-xs" type="button">Click to View Details</button
></a></td>

I cannot seem to make it work in Yajra in the controller:

       return datatables()->of(Form::where('area', 'local')
                                    ->where('submission_type', '=', 'official')
                                    ->orderBy('id', 'DESC')->get()
                              )
                            ->addColumn('details', function($row){
               
                                   $btn = '<a href="viewformdetails/{{$form->id}}" class="btn btn-success btn-xs">Form Details</a>';
                 
                                    return $btn;
                            })
                            ->rawColumns(['details'])
                            ->make(true);

The controller does not properly work on $form->id parameter.

How to pass this parameter to the button?

Thanks, Saad

Aug
22
2 months ago
Activity icon

Replied to Datatables With Yajra - EXPORT HTML5 EXCEL Is Not Working

Yes, this does NOT work well for big datasets with Laravel. So to enable server-side processing, the plugin is Yajra datatables. I am trying to program export buttons in yajra.

Activity icon

Replied to Datatables With Yajra - EXPORT HTML5 EXCEL Is Not Working

Yes, I am using server side approach. How to use download buttons in that system, if i disable default HTML5 buttons of native datatables?

Activity icon

Replied to Datatables With Yajra - EXPORT HTML5 EXCEL Is Not Working

If I remove B, the DOWNLOAD button doesn't show up.

From your second comment, I understood the concept of using yajra button. Can you help me land onto the exact tutorial on that? Many thanks!

Activity icon

Replied to Datatables With Yajra - EXPORT HTML5 EXCEL Is Not Working

    public function viewalldata(Request $request)
    {
       return datatables()->of(Students::orderBy('id', 'DESC')->get())->make(true);
    }

Activity icon

Started a new Conversation Datatables With Yajra - EXPORT HTML5 EXCEL Is Not Working

Hi,

I am trying to use Yajra plugin for using datatables on Laravel. Everything else is working fine, however the HTML5 EXPORT is only downloading the first set of table results which is displayed on the page only (first 10 in the example below). It is not downloading the whole table. Here is my code:

    <script type="text/javascript">

      //Data Tables
      $(document).ready(function () {
        $('#example').DataTable({
          processing: true,
          serverSide: true,
          iDisplayLength: 10,
          aaSorting: [['0', 'desc']],
          dom: 'Bfrtip',
          buttons: [
                { extend: 'excelHtml5', text: 'Download' }
          ],
          ajax:{
                url: "viewalldata",
          },
          columns:[
         {
            data: 'student_id',
            name: 'student_id'
         }
        ],
        });
      });

    </script>

If anyone can help, I would be much obliged.

Thanks, Saad

Jul
25
3 months ago
Activity icon

Replied to Using Pagination With Datatables

My dataset is huge, around 250k entries. I am using MySQL at the backend.

Jul
24
3 months ago
Activity icon

Started a new Conversation Using Pagination With Datatables

Hi,

I am using datatables to display a set of data as a table with options (download, search, etc). For the dataset being big, I have to use paginate() at controller level to divide the results. However, they do not make a good combination, because datatables applies its functions only to the data passed onto it (in my case, its the first 50 results). So, whatever functions datatables offers (download, search, etc) are limited to first page of paginated results by laravel, which is not OK.

Is there a way to make paginate work in coordination with datatables?

If not, then let me know how can I use the SEARCH and DOWNLOAD AS EXCEL function for table while using pagination.

thanks, Saad

Jul
12
3 months ago
Activity icon

Started a new Conversation Uploading API URL File To AWS S3

Hi,

I am receiving some data through an API, which gives me the URL for an image as well. For downloading the image and storing locally, I use the following code:

$car_photo = $request->data[0]['car_photo']['url'];
$imgname = '1.jpg';
file_put_contents('img/carimages/'.$imgname, file_get_contents($car_photo));

This code picks up the URL from API, pulls its content, and saves it locally to a folder.

Now, instead of storing it locally, I want to upload it to AWS s3 bucket. Previously, I was using following code to upload an incoming file through browser upload and put it on s3 bucket successfully:

$request->file('car_photo')->storePubliclyAs('img/carimgs', $imagename, 's3');

But this code assumes that the REQUEST is carrying the file object; while in the new scenario, $request is only carrying a URL and I am pulling the file locally. Hence I cannot use file methods like 'storePubliclyAs', etc.

How can I send the local file to s3?

Thanks, Saad

Jul
10
3 months ago
Activity icon

Started a new Conversation Storing Images On AWS S3, But Unable To Read Them Publicly

Hi,

I am putting images on Amazon S3 through laravel code:

                    $path = $request->file('myphoto')->storeAs('images', $imageName, 's3');

But when I try to read it in the list page, S3 says ACCESS NOT GRANTED.

I have followed exact steps of almost all tutorials for Laravel s3 file uploads, but still unable to fix this. Anyone can guide me to the right tutorial?

Thanks, Saad

Jun
28
4 months ago
Activity icon

Replied to Validation Failing Due To Regex

Still not working...

Activity icon

Replied to Validator Errors Not Filling Form Input Back

@michaloravec Please enlighten me. What are the issues?

Activity icon

Replied to Validator Errors Not Filling Form Input Back

You are right. However, as I am using collective notations for all other types of fields (dropdown, checkbox, etc) and only using simple form for text (I now cannot recall why), I think the better approach is to let form collective handle the whole thing, instead of manually putting old() helper function.

But old() works for sure. I have tested.

Activity icon

Awarded Best Reply on Validator Errors Not Filling Form Input Back

I got the issue. I am not using the LARAVEL COLLECTIVE FORM field format in input. Should fix that.

Activity icon

Replied to Validator Errors Not Filling Form Input Back

{!! Form::text('father_name', null, ['required', 'placeholder'=>'Full Name', 'class'=>'form-control']) !!}
Activity icon

Replied to Validator Errors Not Filling Form Input Back

I got the issue. I am not using the LARAVEL COLLECTIVE FORM field format in input. Should fix that.

Activity icon

Replied to Validator Errors Not Filling Form Input Back

Seems that all my text fields are not picking up the previous values.

 <div class="form-group">
     {!! Form::label('father_name', 'Father name',['class'=>'col-sm-3 control-label']) !!}
     <div class="col-sm-6">
         <input type="text" required placeholder="Full Name" class="form-control" name="father_name"> 
     </div>
 </div>
Activity icon

Started a new Conversation Validator Errors Not Filling Form Input Back

Hi,

I am using following code to return back from validator:

            return redirect('addnewregformpw')
                    ->withErrors($validator)
                    ->withInput();

But few of my form fields are getting the old input, while others are not. I cannot seem to figure out why some of them are working and some are missing. Most of the missing ones are TEXT fields. Is there any form element in blade which takes care of this?

Thanks, Saad

Activity icon

Started a new Conversation Validation Failing Due To Regex

Hi,

I am trying to use this rule based on the value of another field:

'preg_mother_nrc' => ['required_if:preg_mother_nrc_check,Yes', 'regex:/(^[0-9]{2}\/[a-z]{5,8}\((c|nc|ac|v)\)[0-9]{6}$)/iu'],

It is not working correctly, getting triggered for NO value of preg_mother_nrc_check as well (when it should not). I suspect that regex is causing some issue in first half of validation, because another field works fine on this dependency. Can someone please help?

Thanks, Saad

Activity icon

Started a new Conversation Validation Error Messages Customization

Hi,

My variable names are not too readable. When I do validation and error occurs, Laravel display the name of variable in the error message, which is difficult to understand. Is there a way to make laravel use something in blade (id, label, etc) for error message prompts instead of variable names? Please note: I don't want to use custom validation rules, so looking for some shortcut other than that.

Saad

Jun
27
4 months ago
Activity icon

Started a new Conversation Displaying More Than One Fields In SELECT Dropdown

Hi,

I am using Laravel collective for HTML FORMS. For items of dropdown, I am plucking the values and populating through following code:

 @php
      $tcode = DB::table("township_code")->pluck("tcode_en","tcode");
 @endphp
      {!! Form::select('township', $tcode, null, ['class'=>'form-control']) !!}

In blade UI, tcode_en item is visible in dropdown, while tcode item is set as its backend value.

Now, in the UI, I want to show more than one columns, for example, tcode_en as well as its ID [something like: 'place_name (place_id)' in the SELECT dropdown]. How can I populate the select dropdown to show more than one column values of same row item?

Thanks, Saad

Activity icon

Awarded Best Reply on PLUCK Is Giving Lesser Values Than Actual In Table

I resolved the issue. There were duplicate values in my tcode column, due to which laravel was making only unique pairs of tcode_en and tcode, thereby removing around 101 values.

Activity icon

Replied to PLUCK Is Giving Lesser Values Than Actual In Table

I resolved the issue. There were duplicate values in my tcode column, due to which laravel was making only unique pairs of tcode_en and tcode, thereby removing around 101 values.

Activity icon

Replied to PLUCK Is Giving Lesser Values Than Actual In Table

Single pluck is also OK, 423 values for both.

$tcode = DB::table("township_code")->pluck("tcode_en");


$tcode = DB::table("township_code")->pluck("tcode");
Activity icon

Replied to PLUCK Is Giving Lesser Values Than Actual In Table

I am running this:

select `tcode_en`, `tcode` from `township_code`

and it gives 423 values on database

Activity icon

Replied to PLUCK Is Giving Lesser Values Than Actual In Table

$tcode->count() is also giving 322 (wrong value).

Collection array has 322 values. Why not 423?

Activity icon

Started a new Conversation PLUCK Is Giving Lesser Values Than Actual In Table

Hi,

I am running pluck on a table like this:

$tcode = DB::table("township_code")->pluck("tcode_en","tcode");
dd(count($tcode));

The table contains 423 values, but this pluck is giving me 322 values only. I ran the raw code of this pluck on direct database, it gives right value of 423. If I remove any column from the 2 in pluck, it also starts giving right value 423. But the combination is not giving all 423 values, only 322 values.

Help! :-)

Regards, Saad

Jun
23
4 months ago
Activity icon

Started a new Conversation Validation Rule: Unique Except One Value

Hi,

I am creating a profile which should have a unique school ID column. The school ID calculation requires some computation, so I create the profile with empty school ID, and then compute the ID and add to it. This means that empty value may remain there for sometime, before the school ID is computed and updated. Now, as multiple people are creating profiles, at times the empty SCHOOL ID value creates the duplicate constraint issue. I am trying to avoid it.

In validation, how to make the controller check for unique value in a column except the empty/NULL value?

Thanks, Saad

Jun
13
4 months ago
Activity icon

Replied to Log Writing Permission Switching To Root

Yup, you are right. It is interfering with the logs:

    public function handle()
    {
        \Log::info("****** MonthlyregCron process starting...");

Much thanks @snapey! I could never have figured it out.

Activity icon

Replied to Log Writing Permission Switching To Root

I am running a scheduler trigger through cronjob, but the logic behind it is not touching laravel logging (at least I think).

* * * * * php /mnt/hd/www/html/dash/artisan schedule:run 1>> /dev/null 2>&1

But let me go through the trigger logic once again. I think it is generating some logs related to the trigger, if not directly laravel app logs.

Activity icon

Started a new Conversation Purpose Of Key Generation?

Hi,

What is the purpose of key generation for laravel?

php artisan key:generate

I generated a key for one project on server A. Then I moved that whole project to server B by copying the project folder alongwith the code. The key remains the same in ENV file. Is it something bad? Do I have to generate a new key? If yes, would it affect the existing code?

Thanks, Saad

Activity icon

Replied to Log Writing Permission Switching To Root

How to check that?

Activity icon

Started a new Conversation Log Writing Permission Switching To Root

Hi,

I migrated the full laravel project and folder from one server to another. On the new server, I faced issue of log writing permission.

UnexpectedValueException
The stream or file "/mnt/hd/www/html/dash/storage/logs/laravel-2020-06-14.log" could not be opened: failed to open stream: Permission denied

I ran following commands and they fixed the thing.

chown -R root:apache storage
chown -R root:apache bootstrap/cache
chmod -R 775 storage/
chmod -R 775 bootstrap/cache

But today I faced the same issue again. When I check the log directory, it seems that all the new log files are created by root login (instead of apache); that's why when apache tries to write to any new file, it fails.

-rwxrwxr-x 1 root apache 277547 Jun  1 10:32 laravel-2020-06-01.log
-rwxrwxr-x 1 root apache 171631 Jun  2 23:06 laravel-2020-06-02.log
-rwxrwxr-x 1 root apache 128334 Jun  3 17:08 laravel-2020-06-03.log
-rwxrwxr-x 1 root apache 192496 Jun  4 06:46 laravel-2020-06-04.log
-rwxrwxr-x 1 root apache  49597 Jun  5 06:06 laravel-2020-06-05.log
-rwxrwxr-x 1 root apache  11318 Jun  6 20:05 laravel-2020-06-06.log
-rwxrwxr-x 1 root apache  44095 Jun  7 23:00 laravel-2020-06-07.log
-rwxrwxr-x 1 root apache 774273 Jun  8 23:59 laravel-2020-06-08.log
-rwxrwxr-x 1 root apache 871251 Jun  9 23:59 laravel-2020-06-09.log
-rw-r--r-- 1 root root   813600 Jun 10 23:59 laravel-2020-06-10.log
-rw-r--r-- 1 root root   813600 Jun 11 23:59 laravel-2020-06-11.log
-rw-r--r-- 1 root root   813600 Jun 12 23:59 laravel-2020-06-12.log
-rw-r--r-- 1 root root   813600 Jun 13 23:59 laravel-2020-06-13.log
-rw-r--r-- 1 root root    96050 Jun 14 02:49 laravel-2020-06-14.log

I can run the same above commands again, but it will fail again tomorrow. How to make apache create the log file, and not the root login?

Thanks, Saad

Jun
06
4 months ago
Activity icon

Replied to Setting Cron For Model Related Activities

When some action is performed on the student model, the code is configured to capture the logged-in user_id and put it in the database as part of activity performer. This field is indexed to show list of activities of the users when they want to see which activities are performed by their login.

Activity icon

Replied to Handle Dynamic Form Elements Through Jquery In Blade

Seems super! Let me check.

Many thanks! :-)

Activity icon

Replied to Handle Dynamic Form Elements Through Jquery In Blade

Can you explain this a bit more? The error is coming at the front-end blade interface, where the form element says you must enter some fields which are hidden due to user selection.

Do you mean to say that I remove all REQUIRED tags and handle all fields through the validation rules?

Activity icon

Replied to Setting Cron For Model Related Activities

How do I handle the user_id, since the functions I am calling are based on user_id as well?

Activity icon

Started a new Conversation Handle Dynamic Form Elements Through Jquery In Blade

Hi,

I have a form which has a long set of questions. Question number 3 asks if you are a male or a female, and then followup questions are only related to the selection the user does from Q3 dropdown. I am successfully hiding/showing the relevant question set based on Q3 user selection, but the form is parsing the REQUIRED tag for all the questions in the hidden section as well (which I hide through jquery), and does not move forward properly. It's not possible to disable the REQUIRED tag for all question of hidden section, because there are a lot of them.

Can someone guide me to a proper handling of this?

Thanks, Saad

Activity icon

Started a new Conversation Setting Cron For Model Related Activities

Hi,

I have been reading material about how to set a cron in Laravel for scheduling tasks on some time frequency. However, almost all the examples are talking about some activity which is independent of any model or controller (does not engage any model or controller). For example: Sending emails to all users, or cleaning up database, etc. Both these commands are not using the active models in the application (sending email is triggering email app while database cleaning is using direct commands to database table to do something.

        $totalUsers = \DB::table('users')
                  ->whereRaw('Date(created_at) = CURDATE()')
                  ->count();
        Mail::to('[email protected]')->send(new SendMailable($totalUsers));

My requirement is different. I want to invoke a model (e.g. student), check his status at the start of the month (active, suspended, terminated), and post a stipend for him in another model (payment) table. This needs to be done for all the students which are active. This also involves logging user_id into different tables for doing the actions.

How do I do that?

Thanks, Saad

May
06
5 months ago
Activity icon

Started a new Conversation How To Create A Model Associated With Selected Columns Of Another Table

Hi,

I want to create a model which picks up only 5 columns of another table (which has 20 columns - and is connected with a different model). In addition, I also want to add 3 new columns to this model. How do I go about it?

Thanks, Saad

Activity icon

Replied to Linking One Model To Another Without Data Copying

I think you are making instances of same model. $car2 is not a separate model. Is it?

$MyCar is a totally separate model.

Activity icon

Started a new Conversation Linking One Model To Another Without Data Copying

Hi,

I am trying to link one model to another, with all properties inherited, without explicitly re-defining these for model 2. Example: There is a model CAR, which has color and wheels and all other properties. Then I have another model which is MyCar. MyCar should be attached to one of the existing Cars in the model (e.g. Car 1). Now, I don't want MyCar to define all the properties of Car model again, like color or wheels, etc. Instead, it should pick up data from Car model. Like when I say MyCar->color, it should pick up MyCar(Car(1)->color).

Can anyone guide me how to do it, or what to study in docs?

Thanks, Saad

Apr
30
6 months ago
Activity icon

Started a new Conversation How To Create Models Of Info Distributed In Different Tables

Hi,

I have a customer table, which carries around 50 columns in the database. The customer qualifies for different tiers based on certain criteria, like Tier 1, Tier 2, and so on. Each tier has its own set of properties.

In database, the logical design is that I have one main table which carries all new (tier0) customers. For tier 1, I create a new table called tier1, put a foreign key/identifier to customer table, and rest of the columns belong to tier 1 variables. Similarly, tier 2 table also has one foreign key to the main table, and rest its own variables. Note that the variables (i.e. columns) of tiers are not the same.

Now, I want to make multiple models of customers based on the tiers in which they fall. Like, one model for tier1 customer, a different model for tier 2 customer, another model for tier 3 customer, and so on. The model should be able to access all the info of the customer from the main table.

The issue: The model of tier 1 expects all customer attributes to be in the tier 1 table. In other words, it asks me to copy the whole main table into tier 1 table, and then move on. Same is for tier 2 and tier 3 tables.

It does not seem logical to me: A framework addresses same type of optimization, over simple programming.

Please guide me about how to handle this situation, i.e. make multiple models on top of info spread in other than model tables.

Thanks, Saad

Apr
29
6 months ago
Activity icon

Replied to Validation For 'sometimes' Is Not Working

Yes, I seem to have solved it through your advice by doing this:

		'viber' => 'sometimes|nullable|regex:/(^([0]{1}3[1-9])[0-9]{1}[0-9]{5,7}$)/u',

Thanks!

Activity icon

Started a new Conversation Validation For 'sometimes' Is Not Working

Hi,

My page has an optional field, and I am trying to establish its validation. As per docs, this should work:

             'viber' => 'sometimes|required|regex:/(^([0]{1}3[1-9])[0-9]{1}[0-9]{5,7}$)/u',

However, when I don't fill the field in the form (leave empty), the validation throws an error, saying that this field is required, when the validation should kick in only when the field is non-empty (I think).

Can someone help me about how to fix this?

Thanks, Saad