dleroari

dleroari

Fullstack Developer at Global

Member Since 1 Year Ago

New York

Experience Points
9,470
Total
Experience

530 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
68
Lessons
Completed
Best Reply Awards
2
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]aracasts.com 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
9,470 XP
Jan
08
9 months ago
Activity icon

Replied to How Scripts (Linux Commands) Are Executed In Laravel Forge?

No problem. In Laravel Forge, when you create a new site, it runs a set of Linux commands such as installing PHP packages, set up NGINX, changing the .htaccess to target index.php instead of index.html and so forth.

I'm not looking for an architectural description, but simply how these commands are executed.

One way could be having these commands in a GitHub repo which one executes using curl, the second could be through Laravel (I'm just guessing this one) and third we run these commands from a VPN server using SSH.

Activity icon

Replied to How Scripts (Linux Commands) Are Executed In Laravel Forge?

@AURAWINDSURFING - Thanks, but that does not solve my question.

Jan
07
9 months ago
Activity icon

Started a new conversation How Scripts (Linux Commands) Are Executed In Laravel Forge?

Curious to know how scripts (Linux Commands) are loaded in Laravel Forge to set up the environment (PHP packages, Web Server etc) in order to run Laravel.

Do we run these scripts from GitHub using Curl, or do we execute these scripts in Laravel?

In short, how are scripts loaded?

*This question has already been asked on Discord but with no response. Not sure if my question is too broad or not good defined ;)

Dec
13
10 months ago
Activity icon

Replied to Where To Define Controller Methods With Multiple Paths

@snapey , I've seen the video by Adam Wathan, an interesting video with lots of good recommendation.

Thanks, the thing is I'm not using Laravel but ASP.NET Core. So when I create a controller, for instance, CourseUsersController, it creates a path with courseUsers/ where courseUsers is the name of the controller. We also have a dozen types of relationships, and creating a controller between each relation is time-consuming. However, doing so is well worth it as Adam points out.

Compared to Laravel, you create all your routes in Web.php, but in ASP.NET Core you do most of the work inside the controller.

My only option is to choose one of them.

Has anyone been in a similar situation, I'm trying to do Laravel approach in ASP.NET Core, but its really difficult? ;)

Activity icon

Started a new conversation Where To Define Controller Methods With Multiple Paths

I'm a bit stuck in where I should put methods when dealing with paths like this courses/23/users?age=25.

In what controller should I create the action, is it in UsersController or CoursesController?

I would also like to know why it's best doing so if you suggest something.

Jul
02
1 year ago
Activity icon

Started a new conversation Instantiate Elequent Model In Static Function

I need a method that simply returns the id of the first row from the list.


static function firstUser(){
    $users = new App\User; 
        $id = $users->first()->id; 
        return $id; 
 }

When I call the static method Helper::firstUser() I get this error.

PHP Error:  Undefined constant 'App/Utility/App/User' in /opt/lampp/htdocs/.../Utility/Helper.php on line 68

I am well aware of this approach does not work, and that static methods can be invoked without instantiating the class. However, I'm curious to know if there are other alternatives to achieve this solution.

Jun
13
1 year ago
Activity icon

Replied to Change Query Prameters Based On User Input

Thanks, I've made this mistake before, and here is why.

My approach (the wrong one)

<form action="/table" method="get">
    <select>
    @foreach($posts->all() as $post)
        <option name="year" value="{{ $post->date->year }}">{{ $post->date->year }}</option>
    @endforeach 
        
    </select>
    <button type="submit">Submit</button>
</form>

When I use foreach, it seems that the option is only one input, and that is why I include the name attribute inside option element instead of the select attribute.

As you mentioned, this is the accurate approach

<form action="/table" method="get">
    <select name="year" >
    @foreach($posts->all() as $post)
        <option value="{{ $post->date->year }}">{{ $post->date->year }}</option>
    @endforeach 
        
    </select>
    <button type="submit">Submit</button>
</form>

Thanks, I was trying all sort of approaches.

Activity icon

Started a new conversation Change Query Prameters Based On User Input

The query string I am dealing with is /table?id=1&year=2018&month=6.

I have a search component with three dropdown fields; id, year and month along with submit button.

On the same page, I have a table below the search component.

For instance, if use selects; id = 2, year= 2015 and month=5 and hit submit, I want the URL to change to /table?id=2&year=2015&month=5.

I've seen different approaches, and also tried a form with GET method, but it did not include the query parameters for some strange reason, the result I got was /table.

I'm sure there is something I am doing wrong or not thinking of, any practical ways of achieving this?

Activity icon

Replied to Prevent Users From Accessing High-sensitive Data By Simply Changing Query String

@Vilfago, thanks. But I have that setup. As mentioned my concern is more about securing teachers (admin) from accessing private data by simply changing query string.

To put it in perspective, only one teacher is responsible for 10 students. We cannot have two teachers responsible for the same students.

Jun
12
1 year ago
Activity icon

Replied to Grouping Records To Create Chart Data

I've been researching a couple of forums, and most of them either over-complicate things, or not a part of what you are looking for.

Here is a simple approach that shows number of threads created for each day.

Don't let lines of code scare you, once you read it you'll understand the rational thinking.

$threads_created_daily = []; 

// Unique days 
$uniqueDays = $posts->get()->groupBy(function($item) {
  return $item->created_at->day;
});

// Count number of posts for each day
foreach($uniqueDays as $day => $threads){
  $threads_created_daily[$day] = $threads->count(); 
}

// Dump data
dd($threads_created_daily); 
// array:6 [▼
//   28 => 1
//   "01" => 2
//   "02" => 6
//   "06" => 1
//   "09" => 3
//   11 => -4
// ]
Activity icon

Replied to CMS

Activity icon

Replied to Export Pdf In Laravel

What is the error?

Activity icon

Started a new conversation Prevent Users From Accessing High-sensitive Data By Simply Changing Query String

I am dealing with this app that provides the teacher the ability to manage students within a class project. I was thinking making this public, so that teachers all around the world can use it.

One of my main concerns is related to separation of these teachers. For instance, if I create a sign-in/sign-up page, how would I separate the teachers along with their students in terms of privacy?

An example, lets say we have this query string platform.com?teacher=John+Doe/students that simply shows all the students that have John Doe as teacher.

Now the problem here is that if someone simply changes the query string from platform.com?teacher=John+Doe/studentsto platform.com?teacher=Peter+Berkley/students he will get students enrolled in Peter Berkley's class, which is privat and not allowed.

How can prevent this from happening?

May
24
1 year ago
Activity icon

Started a new conversation How To Handle MVC The React Way

Alright, the research has shown that React is simply a javascript user-interface library for creating reusable components.

In short, it sounds like React only focuses on the V (view) from MVC design-framework.

I am curious to know what alternatives React has in terms of setting up a design-framework that handles both frontend and backend?

Additionally, I've been working with Laravel lately, and don't see the need for using React thus blade templating provides similar capabilities.

May
15
1 year ago
Activity icon

Replied to Multiple Date Selecte In Single Input Field And How To Store Separately?

I am using this one by Amsul pickdate.js. Similar to what @madsem have shown above, but I've also made it possible to format the inputs so that I can easily capture what I need without doing any formatting in Laravel.

$(#idName).pickadate({
    formatSubmit: 'dd.mm.yyyy', 
    firstDay: 1, // Starts on Monday
    disable: [7] // Prevent user from selecting Sunday
});

And then when user submits

$request->input('nameOfTheInputField'); 

There are many more options, for instance change the name of the dates to your preferable language, limit what days are available. Similar to date, they also include picktime() for hours. For instance, user can select what time of the day he is at work. In addition, you can limit the time only from 08:00 AM to 15:00 PM and so forth.

The documentation is also well written, click here.

Btw, it provides two themes, I use classic.

Activity icon

Replied to Laravel Notification Not Working

"Notification::send() requires the first argument to be an object, usually one that uses the Notifiable trait. You pass just a string holding email address, hence the error."

Check this post on stack overflow

Do you have similar problem?

May
09
1 year ago
Activity icon

Replied to Check If Query Update

Last question, have you checked visually if the record is updated?

Activity icon

Replied to Check If Query Update

What exactly fails, can you do a dd($update) to check what value you receive when it fails, is it null, false etc.

Activity icon

Replied to Controller Is Not Working When Ajax Request Is Fired

Did you manage to solve the issue? If not, can you rephrase the the last reply, difficult to understand.

Activity icon

Replied to Check If Query Update

I am not sure how you have structured your conditional if-statement. However, when the query updates the value(s), it returns true. Everything except that means it failed. In that case, simply place the variable in an if-statement like shown below:

Try this:

// $udpate is true
if($update){

    // Update was successful

}else{
    
    // Update failed

}


May
06
1 year ago
Activity icon

Replied to Handle Auth And Non-auth Api Requests - What Is The Best Design

TL;DR: I would not recommend creating separate files using roles as controller name (like AdminController, EmployeeController) because then you limit your application towards roles rather than functionality. So instead, create a controller such asDashboardController where all methods are associated to admin roles.

With Laravel, you can easily achieve this by using middleware and __construct().

middleware works like a bridge, where every page request must go through before it can show the page. Let me show you.

Create a new middleware class CheckRole.php: If user have role employee, and tries to access admin page, he will get error 404. Otherwise, the request will continue.

class CheckRole
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    // AfterMiddleware
    public function handle($request, Closure $next, $role)
    {

        // Validate if user has role
        if(! Auth::user()->hasRole($role)){
            // Redirect
            return abort(404, 'Unauthorized');
        }
        
        return $next($request);
    }
}

Notice: the hasRole() is simply a method I made in model User.php.

// Returns true or false
public function hasRole($role){
    return null !== $this->role()->where('name', $role)->first();
}

Then, inside the controller, I assume you have some methods for admin and employee which you want to limit. If that is the case, you can use except() to prevent access to some methods.

Controller

function _construct()
{
    // employee can access all methods except create, update, delete
    $this->middleware('role:employee')->except(['create, update, delete']); 
}

Alright, so in short, whenever a request to a specific method inside this controller is executed, the middleware class CheckRole sees if the authenticated user has role employee (the string after role: is the value we pass) it will continue the request. As you can see, we are limiting the employee to create, update or delete, thus meaning admin can access these methods.

I've wrote an article on Medium that shows how to redirect user after login depending on type of role.

May
04
1 year ago
Activity icon

Replied to How Does It Work When Creating New Instance In Php Artisan Tinker

Thanks @Cronix, but I still don't understand the connection. Is Tinker a part of composer or a feature that Laravel provides.

Activity icon

Replied to How To Send Value From Modal To Modal Input Using Java

First of all, you need a submit button inside the form in order to capture the inputs in controller (if you already have then avoid this). Secondly, if you want the selection to be shown in the second modal, you can pass the value ´{{ $purpose->name}}´ as a route parameter like `href="/{{ $purpose->name}.

Web.php

    // {name} is the value you've passed which is $purpose->name
    Route::get('/{name}', ´NameController´); 

Controller

    public function index($name) {

        $purposes = Purpose::all(); 

        // Assign the passed value
        $value = $name; 

        return view('reports.view-reports', compact('purposes','value')); 
    }

In short, there are three steps required if you want to pass a value to another model; (1) pass the value to href in html, (2) pass the value to the controller and (3) last but not least, capture the value inside method, in our case index($name).

Activity icon

Replied to Redirection To Https

It depends on what web-server you have, Nginx or Apache. If you are using a Virtual Private Server such as DigitalOcean or Vultr, you must setup up this security yourself. Otherwise, if you use an existing domain server, they might already have that part included. This is not something you can do within the Laravel app, but with the web-server you are using.

Activity icon

Replied to How To Create A Link In Javascript With Laravel

It feels like you want something like php artisan route:list. It shows you all the routes you have in your application.

Activity icon

Replied to Laravel Relationship Not Working As Expected

Then the relationship between trainer and student would be: Trainer hasMany() students. Students belongsToMany() Trainers.

Activity icon

Replied to Notification::fake() Is Sending An Actual Email

Have you included the use Illuminate\Support\Facades\Notification; library?

Activity icon

Replied to Can't Add Post With # In Title

Can you please share the code?

May
03
1 year ago
Activity icon

Started a new conversation How Does It Work When Creating New Instance In Php Artisan Tinker

General question: I am aware of that if I write php artisan tinker, and then type $faker = Faker\Factory::create(); I can access the methods in that class. However, how does tinker know exectly which class to find just by typing Faker\Factory. Do namespace have something to do with this, how is the class found? In other words, how does tinker find these classes?

Apr
24
1 year ago
Activity icon

Replied to External Class Issues

First of all, it is not good practice to call too many static methods or in any other methods directly from the controller in blade template. You will end up with code that looks messy and difficult to read. The controller shall interact with web.php through routes.

However, let us say you need an external class with methods that handle special operations such as; calculate values, convert string to array and so on. In that case, I would create a folder called Utility in App directory. And in that folder I would have a helper.php class that holds all kinds of methods (static methods too).

Create App/Utility/Helper.php, keep in mind to include namespace so that you can access the class.

<?php
namespace App\Utility; 

class Helper {

    // Sum values
    static function sum(a,b){
        return a + b; 
    }
    
}

Then call it blade like:

<div>
    <p>{{\App\Utility\Helper::sum(2,5)}}</p> // Returns 7 obviously :)  
</div>

However, this does not look pratical, imagine if you have 10 static methods, and must prefix \App\Utility\Helper 10 times! How can we make this look cleaner? The solution is; create an aliases in config/app.php.

'Helpers'   => 'App\Utility\Helpers'

Then update blade:

<div>
    <p>{{Helper::sum(2,5)}}</p> 
</div>

Last but not least, everytime you change something in config directory in Laravel, run php artisan config:clear.

Activity icon

Started a new conversation Remembering Id When Time Is Ended

I've made an application with two buttons start and stop which simply starts/ends a timer. In that case, I am trying to capture the difference simply by using Carbon, when the user started and ended the time (from/to).

I have two routes /startTime/{$id} and /endTime/{$id} that sends the user ID to a controller class.

It is easy to setup the start button functionality that simply adds a record to the database with (id=3, startDate=23.05.2018, startTime=08:00, endTime=0 ) where endTime is created only when user clicks stop.

The challenge is when user stops the timer, how can I locate the same record (id). In other words, how can the ID be remembered between two routes?

In addition, I was thinking maybe I can store all the $record to the server once the user clicks stop.

Apr
12
1 year ago
Activity icon

Replied to Where Are You All From?

Kurdistan.

Activity icon

Replied to Laravel 5.2 -> Laravel 5.6 Framework Upgrade

I see the reasoning applying these changes, but I would really think about it, if it is necessary.

Also remember, before doing any changes/upgrade, make sure you back-up the project, so that you can simply go back if you anything went wrong.

This thread is similar topic.

Good luck.

Mar
24
1 year ago
Activity icon

Replied to Change Blade View From Create To Edit Form When Button Is Triggered

@Snapey, @Shredder and @mdeorue thanks for the feedback. As Snapey mentioned, this is a frontend issue. I'll go for JS.

Activity icon

Replied to Date From Form Datepicker

Here is the approach: (view.blade.php -> web.php -> controller)

Html (viewName.blade.php)

<div class="field-body">
    <div class="field">
        <p class="control">
            <input class="datepicker" type="text" placeholder="Select date" name="dateFrom" >
       </p>
    </div>
</div>

The name="inputName" property allows laravel to know what type of input field you want when using request.

Web.php

    Route::post('/view', '[email protected]'); 

controllerName.php

    public function getDate(Request $request){
    
        $date = $request->input('dateFrom');
        dd($date); 

    }

Keep in mind, if you want to pass input fields to controller, you must have the them wrapped inside a form, like this.


<form method="POST" action="/view">

    <!-- Declare input fields -->

</form>

Mar
23
1 year ago
Activity icon

Started a new conversation Change Blade View From Create To Edit Form When Button Is Triggered

So I have have two @include views in one blade template; first view is create.blade.php form and the second is table.blade.php. Next to each table row, there are two buttons - edit and delete.

The goal is to change the create.blade.php view to edit.blade.php when edit button is triggered.

This is somehow related to SPA functionality - is there a way to achieve this with blade templates, I am thinking of using if statement inside the blade.. Any tip? If nothing works I'll use ajax calls.

Here is how the code looks like:

@include('create.blade.php') <-- When button edit is triggered, change this to edit view.

@include('table.blade.php')
Mar
08
1 year ago
Activity icon

Replied to I Want To Use JavaScript, But It Seems That Laravel Can Do Most Of It

@bashy, @CJJ and @topvillas thanks for the insights. It amazes me how many frameworks, programming languages, and approaches there is to solve a problem. We live in a world with exponential technological growth. Sometimes even though one might feel he has everything under control, can drift away.

Another thing I have been thinking of; I see that Laravel has become extremely popular lately, it has over 35 mil downloads on Github. Does this mean that it is time to learn something new?

Activity icon

Started a new conversation I Want To Use JavaScript, But It Seems That Laravel Can Do Most Of It

Strange as it sounds. I started learning JavaScript a couple of months back, and thought that I had finally found a programming language I'll stick too.

But then, my friend introduced me to Laravel, and ever since, I've been using Laravel.

While building these apps with Laravel, I see that most of the work I've done previously with JavaScript/jQuery, can be done with Laravel quicker/simpler.

I know that at some extent, I will use JavaScript/jQuery to run single page operations.

Don't get me wrong, I love Laravel, and I am aware of that it is PHP. But I also like JavaScript and want to become better at it.

It is difficult to describe the feeling, it feels like you have bought a new car that works perfectly, and you don't want to sell it, because you have good memories.

Is there someone else that have experience similar, not only between Laravel and JavaScript, but other types of langauges?

Activity icon

Replied to Web Host And Version Control - Remote Access

@Cronix, thanks. But I am using web host. All the files are uploaded to their site.

@Nash, I have been looking at Digital Ocean and Fortrabbit, just for my own curiosity, which of them do you recommended?

I am simply looking for something that I can maintain version control while still being able to run normal git commands (add, commit and push).

Mar
07
1 year ago
Activity icon

Replied to Multiple Functions For Resource File

I guess I know the solution, but to be certain. What is the name of the file, can you post the code here?

Activity icon

Replied to How To Make A Dropdown List Suggest Only Options In Relation With A Selected Value?

Form isn't included in laravel 5.0 as it was on 4.0.

Pedro Lobito has posted something that might help you.

https://stackoverflow.com/questions/28753767/laravel-5-class-form-not-found

I hope it helps.

Activity icon

Started a new conversation Web Host And Version Control - Remote Access

I am trying to figure out what is a practical way of managing version control (Github) when your site is running on a web host.

Currently, I am accessing code remotely using FileZilla. However, whenever I do code changes, I need to manually update Filezilla. This process can be time-consuming. In addition, I've also used some of the plugins provided by Visual Studio Code for ftp remote access, but they are not viable.

Is there a way, a program or tool that allows you to apply changes while maintaining version control?

Mar
03
1 year ago
Activity icon

Started a new conversation Prevent User From Changing Button State From Inspect Element

I have a button that simply submits the form when user has filled out the required fields. After user have submitted, the button is disabled.

Since the html is shown in client-side, everyone has the ability to access "Inspect Element" and manually remove disabled, thereby submit the form.

Is there a way I can prevent the user from doing this?

I use ternery statement to disable the button. ​

{{ ($status > 0 ? 'disabled' : '') }} 
Feb
21
1 year ago
Activity icon

Replied to Set Up Approval List For User Timesheet

One way to solve this problem is to use relationships, I need to add two new field of columns in approval list, one for user_id, and the other for timesheet_id.

Feb
20
1 year ago
Activity icon

Started a new conversation Set Up Approval List For User Timesheet

I am not looking for a programming solution, but recommendations related to the approach.

Short app description: The application allows the user to log hours he/she has worked during that day on a monthly timesheet. For instance, Bob has logged hours for 15 days in January, 2018. John has logged hours for 20 days in March, 2018 etc.

The logic I am trying to set up is challenging. After the user has completed the timesheet, he must click on the button that says "Request Approval", which then notifies the admin that the user has completed and waiting for approval.

What I have done so far: I have created an approval table (without any relationships) that holds the id, username, date, status which I create/insert data whenever the button is triggered through a requestApproval() method in ApprovalController.

Maybe I am on the right path, or I am making it too complex. Any recommendations on how to set up an approval list that is connected with the user timesheet?

Feb
16
1 year ago
Activity icon

Replied to How To Access Variables Declared In Blade Template From Controller Method

Actually, there is another solution which does not require form nor ajax, and of course much more out there.

But anyway, the solution that seems to work for me is to use query string to send data. I also tried using routing parameters, but this requres more code. Since I am a lazy programmer, I choose query strings.

How it looks in blade.php


href={{ route('requestApproval') }}/?username={{ $username }}&date={{ $date }}&status={{ $status }}

I then capture this data in controller like:


$username = request('username');
$date = request('date');
$status = request('status');

Of course, one can argue and say this is not optimal, but guess what, it works :)

Btw, this is not convient for large junks of data..

Thanks for the support.

Activity icon

Replied to How To Access Variables Declared In Blade Template From Controller Method

@biishmar, I am sorry but this is not the solution I am looking for.