dleroari

dleroari

Member Since 1 Year Ago

New York

Fullstack Developer at Global

Experience Points 9,470
Experience Level 2

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] 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.

08 Jan
6 months ago

dleroari left a reply on 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.

dleroari left a reply on How Scripts (Linux Commands) Are Executed In Laravel Forge?

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

07 Jan
6 months ago

dleroari 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 ;)

13 Dec
7 months ago

dleroari left a reply on 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.

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

dleroari 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.

For instance, if I have a UsersController, and a CoursesController, then where should this method to handle the path be put?

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

02 Jul
1 year ago

dleroari 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 static(App\User); 
        $id = $users->first()->id; 
        return $id; 
 }

Error

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

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

13 Jun
1 year ago

dleroari left a reply on Change Query Prameters Based On User Input

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

My approach

<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.

dleroari left a reply on 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?

dleroari 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 `subm 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 `subm, I want the url to change to `/table?id=2&year=2015&month.

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?

dleroari left a reply on 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.

12 Jun
1 year ago

dleroari left a reply on 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
// ]

dleroari left a reply on Export Pdf In Laravel

What is the error?

dleroari 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?

24 May
1 year ago

dleroari 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.

15 May
1 year ago

dleroari left a reply on 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.

dleroari left a reply on 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?

09 May
1 year ago

dleroari left a reply on Check If Query Update

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

dleroari left a reply on Setting Up Laravel On Ubuntu 16.04

@champ2152, a question for my own curiosity, do you work for Kongsberg Defence Systems?

dleroari left a reply on 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.

dleroari left a reply on 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.

dleroari left a reply on 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

}


06 May
1 year ago

dleroari left a reply on Handle Auth And Non-auth Api Requests - What Is The Best Design

I would not recommend creating separate files for different user roles. With Laravel, you can easily achieve this by using middleware and __construct().

middlewareI 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);
    }
}

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 cannot access these methods
    $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), and if it does, 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 the login in terms of roles.

04 May
1 year ago

dleroari left a reply on How Does It Work When Creating New Instance In Php Artisan Tinker

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

dleroari left a reply on 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). Inputs can only be captured after user have clicked the submit button. 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')); 
    }

dleroari left a reply on 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.

dleroari left a reply on 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.

dleroari left a reply on Laravel Relationship Not Working As Expected

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

dleroari left a reply on Notification::fake() Is Sending An Actual Email

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

dleroari left a reply on Can't Add Post With # In Title

Can you please share the code?

03 May
1 year ago

dleroari 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?

24 Apr
1 year ago

dleroari left a reply on External Class Issues

First of all, it is not good practice to call static methods or in any other methods in general, directly from the controller through 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.

dleroari 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.

12 Apr
1 year ago

dleroari left a reply on Where Are You All From?

Kurdistan.

dleroari left a reply on Laravel 5.2 -> Laravel 5.6

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.

24 Mar
1 year ago

dleroari left a reply on 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.

dleroari left a reply on Date From Form Datepicker

Here is the approach:

Html

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

Web.php

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

controllerName.php

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

    }
23 Mar
1 year ago

dleroari 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, one is create.blade.php form and the other is a table.blade.php. Each table row, has two buttons, one is edit and the second is 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?

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')
08 Mar
1 year ago

dleroari left a reply on 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?

dleroari 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?

dleroari left a reply on 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).

07 Mar
1 year ago

dleroari left a reply on 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?

dleroari left a reply on 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.

dleroari 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 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 provides allows you to apply changes while maintaining version control?

03 Mar
1 year ago

dleroari 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.

{{ ($status > 0 ? '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?

21 Feb
1 year ago

dleroari left a reply on 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.

20 Feb
1 year ago

dleroari 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?