papa

Member Since 3 Years Ago

Experience Points 8,615
Experience Level 2

1,385 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 29
Lessons
Completed
Best Reply Awards 5
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.

02 May
2 weeks ago

papa left a reply on Documenting Your New Project

@zetecvan JIRA Confluence and Ticketing system maybe

15 Apr
1 month ago

papa left a reply on Extract Only Useful CSS Files/rules And JS Code

You can merge all your css files in one file and the same for js files

12 Apr
1 month ago

papa left a reply on Dealing With Huge Tables And Pagination

Do you use the Datatables plugin with ajax calls?

papa left a reply on How To 'compose' The Route Definitions?

One think that you can do is this

foreach(File::allFiles(__DIR__.'/web') as $file) {
    require $file->getPathname();
}

where in web folder you have multiple files of routes

A second option is to add some code in RouteServiceProvider

as an example

protected function mapModuleRoutes()
    {
        foreach ($this->modules as $module) {
            if (file_exists(app_path('Modules/' . $module .'/routes.php'))) {
                Route::middleware('web')
                    ->namespace($this->namespace)
                    ->group(app_path('Modules/'. $module . '/routes.php'));
            }
        }
    }

Here I have modular structure and each module has its routes.php file

10 Apr
1 month ago

papa left a reply on Custom Collections In Child Models

@ Yes, you may create RepositoryClass for Refill, Car e.t.c. and from their you can add methods to get your data

papa left a reply on Custom Collections In Child Models

@placeholdermeme

Yes, I think is beautiful to do

$car->getAverageMpgByMonth() 


public function getAverageMpgByMonth()
{
    return $this->refills()->avg();   // or you can use here foreach refills()
}

papa left a reply on Question About View Sharing

You can use in your ServiceProvider

public function boot()
    {
        // Share User details to all view
        View::composer('*', function($view) {
                $view->with('user', Auth::user());
        });
}

Just add your code

papa left a reply on Custom Collections In Child Models

refills() will return you a collection of many. Thus you can not do it.

Think about https://laravel.com/docs/5.8/collections#method-average

or

$car->avgRefills()

and in Car model

public function avgRefills()
{
    return $this->refills()->avg();   // or you can use here foreach refills()
}
08 Apr
1 month ago

papa left a reply on Applying Design Patterns In Laravel

Think about Strategy and Factory Patterns

class PaymentFactory
{
    private $payments = [
        'paypal' => PayByPaypal::class
    ];

    public function createPaymentObject(string $payment)
    {
        $paymentClass = $this->payments[$payment];

        if (class_exists($paymentClass)) {
            return new $paymentClass;
        }

    // exception
    }
}

trait PaymentTrait
{
    protected $paymentsTypes = [
        'paypal' => 'Paypal'
    ];

    public function getPaymentTypes(): array
    {
        return $this->paymentsTypes;
    }
}

interface PaymentStrategy
{
    public function pay();  
}

class PayByPayPal implements PaymentStrategy
{
    public function pay()
    {
        // here you will implement the PayPal API
    }
}

class PaymentController extends Controller
{
    public function pay(Request $request)
    {
        Session::put('payment', $request->input('payment'));

        return ((new PaymentFactory())->createPaymentObject($request->input('payment')))->pay();
    }
}

papa left a reply on Applying Design Patterns In Laravel

Imagine you have a Controller

class MyController extends Controller { protected $userService;

public function __construct(
    UserServiceInterface $userService
)
{
    $this->userService = $userService;
}
public function index()
{
    return view('test')->with(
        'user' => $this->userService->getUser()
    )
}

}

interface userServiceInterface { public function getUser(); } class userService implement userServiceInterface { public function getUser() { return Auth::user(); } }

class UserServiceProvider extends ServiceProvider { public function register() { $this->app->bind(UserServiceInterface::class, UserService::class); } }

The same classes for Repository: UserService => UserRepository UserServiceInterface => UserRepositoryInterface

papa left a reply on Applying Design Patterns In Laravel

First think about using Service Layer Design Pattern and Repository Design Pattern with Constructor Dependency Injection.

22 Mar
1 month ago

papa left a reply on Test Validation Email Unique Fails Always

@tykus found it

should change the sequence between the validation and the registration

foreach ($users as $user) {
            $validator = Validator::make($user, (new UserRequest())->rules();
            $this->assertEquals(false, $validator->fails()); // $this->assertTrue($validator->passes());

            $response = $this->post(route('doRegister'), $user);

I apologize if you have found my comment offensive, it was not like that. Thanks for your support.

papa left a reply on Test Validation Email Unique Fails Always

@tykus Firstly: of course the $this->id is not set and is null and the rules() are

return [ 'firstName' => ['required'], 'lastName' => ['required'], 'email' => ['required', 'email', 'unique:User,email,null,id'], 'password' => ['required', 'min:6', 'confirmed'], 'password_confirmation' => ['min:6'], 'address' => ['required'], 'zipcode' => ['required'], 'city' => ['required'], 'phone' => ['required'], 'language' => ['required'] ];

Secondly: this Rule::unique('User')->ignore($this-id) is the same with this 'unique:User,email,null,id'. I have both tested.

Third: A feature test should be testing your application code, not the framework. Where I test the framework??

21 Mar
1 month ago

papa left a reply on Test Validation Email Unique Fails Always

What I get in log file local.INFO: {"email":["validation.unique"]}

papa left a reply on Test Validation Email Unique Fails Always

@TYKUS - Yes all my tables starts with capital letter

papa started a new conversation Test Validation Email Unique Fails Always

public function rules() { $id = (isset($this->id) ? $this->id : null) . ',id';

    return [
        'firstName' => ['required'],
        'lastName' => ['required'],
        'email' => ['required', 'email', 'unique:User,email,' . $id],
        'password' => ['required', 'min:6', 'confirmed'],
        'password_confirmation' => ['min:6'],
        'address' => ['required'],
        'zipcode' => ['required'],
        'city' => ['required'],
        'phone' => ['required'],
        'language' => ['required']
    ];
}

$users = [ [ 'firstName' => 'Name', 'lastName' => 'Surname', 'password' => 123456, 'password_confirmation' => 123456, 'address' => 'My address', 'zipcode' => '84763', 'city' => 'New York', 'email' => 'mail1@example.com', 'phone' => '017654875674', 'mobile' => '763636', 'language' => 1 ], ];

foreach ($users as $user) { $response = $this->post(route('doRegister'), $user);

        $validator = Validator::make($user, $validation->rules());
        $this->assertEquals(false, $validator->fails());

        $this->assertDatabaseHas('User', ['email' => $user['email']]);
        $this->assertDatabaseHas('Member', [
            'firstName' => $user['firstName'],
            'lastName' => $user['lastName'],
            'address' => $user['address'],
            'zipcode' => $user['zipcode'],
            'city' => $user['city'],
            'phone' => $user['phone'],
            'mobile' => $user['mobile'],
            'langId' => 1
        ]);

        $response->assertRedirect(route('index', 200));
    }

The $validator gives me always error on Email Unique Rule and the test does not pass. Have someone an idea why that happens?

01 Dec
5 months ago

papa left a reply on How To Pass Dynamic Selector Value To Jquery

@nonanovi just type in your html

and in jQuery

var id = $(this).data("id")

16 Nov
6 months ago

papa started a new conversation Does Envoyer CI And CD Both?

Hello Team,

does Envoyer Continuous Integration (CI) and Continuous Deployment (CD) as Jenkins or Circleci does??

For my view it looks that Envoyer idoes only CD and not CI.

24 Sep
1 year ago

papa started a new conversation Service Provider IoC, Bindings Diferrence

I have in my service Provider the following code in register function

use App\Modules\Core\Includes\Services\Human;


$this->app->bind('human', 'App\Modules\Core\Includes\Services\Human');
$this->app->bind('human', function() {
    return new Human();
});

What is the difference between this two binding ?

12 Sep
1 year ago

papa left a reply on How To Delete A Records Which Its ID Not Exists In Another Tables ?

@bashy yeah I guess something like this.

function deleteUser($id)
{
    // Here the relations to check if exists at least on a record
    // of 1 of 10 Tables
}

papa started a new conversation How To Delete A Records Which Its ID Not Exists In Another Table ?

Hi,

I have a table of users

Users
id, first_name, last_name
1, Tom, Baar

and also I have **10** tables where all of them have a column which is the foreign_key of user_id

e.x.

Contracts
id, name, contract_manager(foreign key of users table)
1, Servers, 1

My question is how can I check if the user_id who I want to delete exists in one of the 10 tables it is associated so that I prevent the deleteion of the user ?

06 Sep
1 year ago

papa left a reply on SQLSTATE[HY000]: General Error: 1215 Cannot Add Foreign Key Constraint

Schema::create('posts', function (Blueprint $table) {
            $table->increments('id')->unsigned();
        $table->integer('sr')->nullable();


Schema::create('updates', function (Blueprint $table) {
            $table->increments('id');
        $table->integer('sr_id')->unsigned();
        $table->text('update');
            $table->timestamps();
        });

Schema::table('updates', function ($table) {
        $table->foreign('sr_id')->references('id')->on('posts')->onDelete('cascade');
        });

papa left a reply on Laravel Beginner Wants To Become A Full Time

Yes is needed a PHP background and basically an Object-oriented programming. You can start looking about classes and how they collaborate. You can find on google tutorials about PHP and classes. Open an Editor and start typing.

papa left a reply on Localization Set A Locale

@janakaontomatrix you may use also a middleware.

05 Sep
1 year ago

papa left a reply on Creating A New Command

!!!cannot follow!!! @eshaparvathi

papa left a reply on Creating A New Command

@eshaparvathi can you post code...

papa left a reply on How To Pass Dynamic Selector Value To Jquery

@bipin think about something like this

   <select class="selectpicker form-control " id="applicantstatus_{{$s->id}}" name="applicantstatus_{{$s->id}}" data-style="btn-info btn btn-xs" data-posttd="{{$s->id}}" data-width="auto" >

 $('.setvalue').on('click', function() {
       var id = $(this).data("id");
       var inp =  $('#applicantstatus' + id).val();

papa left a reply on None Of My Routes Work Except For The '/' - New Laravel 5.5 Install

@jpeterson579 check if you can open your routes typing localhost/laravel/index.php/myroute

papa left a reply on Error : Internal Server Error

@muazzamazaz It may be your url, try without slash /

url: 'delprofile',
04 Sep
1 year ago

papa left a reply on Custom Message In Validator Laravel 5.5

Try

request()->validate([
            'name' => 'required',
            'id' => 'exists:doc_contractors,id'
        ], [
            'name.required' => 'name is required',
            'id.exists' => 'invalid id'
        ]);

papa left a reply on I Got Suggestions And Errors In Terminal After Creating New Project In Laravel

@archiebango looks ok your output.... try to create a new project and check that out.

papa left a reply on Custom Message In Validator Laravel 5.5

$messages = [
    'required' => 'The :attribute field is required.',
];

$validator = Validator::make($input, $rules, $messages);

papa left a reply on 127.0.53.53 When Pining Laravel Project !!!

@Nasr1 as said dont use Chrome and you may change also the tld

papa left a reply on 127.0.53.53 When Pining Laravel Project !!!

127.0.53.53 is a special IPv4 address that will appear in system logs alerting system administrators that there is potential name collision issue, enabling a quick diagnosis and remediation. The "53" is used as a mnemonic to indicate a DNS-related problem owing to the use of network port 53 for the DNS service.

papa left a reply on Printing Message

@davy_yg Post code to figure it out!

03 Sep
1 year ago

papa left a reply on 1066 Not Unique Table/alias

@qWici you try to implement pivot relatioship

This is not ok. This should be a third table with which Beers and Users are connected. Need to be removed from there.

protected $table = "user_beers_data";

USER MODEL
public function beers()
    {
        return $this->belongsToMany(Beers::class, 'user_beers_data', 'user_id' 'beer_id');
    }
BEER MODEL
public function users()
{
    return $this->belongsToMany(User::class, 'user_beers_data', 'beer_id', 'user_id');
}

papa left a reply on Accessor Not Being Executed

@vkronlein maybe the problem is on === . Check the values of variable $value. Maybe is not the same $value === 'on' or not same datatype $value === 1

papa left a reply on Redirect User To A Route After Registration

Why dont you use code like this

return redirect()->route('home');
01 Sep
1 year ago

papa left a reply on Redirect If 404

use Exception;

public function handle($request, Closure $next, Exception $e) {

if ($e->getStatusCode() == 404) {
    return redirect(\Config::get('app.front_url'));
}

}

not tested but you can try

papa left a reply on Redirect If 404

@Waldemar normally the Config::get('app.front_url') can return the fronts_url route and you may write

return redirect(\Config::get('app.front_url'));

papa left a reply on Redirect If 404

@Waldemar if error you can write abort(404);. Then you can have a 404.blade.php page in resources/views/error folder.

papa left a reply on Export Data To .csv

@tk90 is totally easy to learn how a package works. There are some good. I would suggest you XLSX writer https://github.com/mk-j/PHP_XLSXWriter with examples included

papa left a reply on Is Is Necessary To Always Create Column Created_by In Table While Inserting Data In Table Using Save() Method?

This should happen because you havent set in Model of the table

protected $timestamps = false;

This way the created_at and updated_at will be ignored. If you may need in future to record such an info you can use your custom columns than laravels and save them as timestamp and work with Carbon with them.

papa left a reply on VerifyCsrfToken - Composer Update In Production

Firstly if your project is under git then you can git reset --hard and delete your vendor folder. Then run composer install to rebuild it.

papa left a reply on Filter Record Using From Date And To Date

You use timestamps as dates or DATE style ex. 01/01/2017 ?

 if ($request->has('from_date')) {
        $user->where('date_of_visit', '>=', $fromDate);
        }

if ($request->has('to_date')) {
        $user->where('date_of_visit', '<=', $toDate);
        }