tykus

tykus

Full Stack PHP Developer at Linked FInance

Dublin

Member Since 4 Years Ago

Experience Points 747,600
Experience
Level
Lessons Completed 1385
Lessons
Completed
Best Reply Awards 1141
Best Answer
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.

17 Jan
16 hours ago

tykus left a reply on Auth()->user() Does Not Have Methods In User Model(laravel-ide-helper)

Assign a variable and add an annotation to give your IDE a typehint (within the scope that the variable will be used):

/** @var App\User $user */
$user = auth()->user();

tykus left a reply on How To Show In Vue Tan

Answer my question.

Lol. You're not going to get much help with that attitude.

Your question is unclear; here is the question you have asked (according to my understanding): you are showing images for PHPMyAdmin (which most likely you didn't write) where you want to click on a value and programmatically open the Vue devtools tab? Really?

16 Jan
1 day ago

tykus left a reply on Constructor In Library (not Controller)

use Lib\TestingLib; achieves nothing other than alias (makes available) that TestingLib class in the controller. You will new to new TestingLib() or inject that class into the Controller's constructor which will instantiate it (if it can be resolved):

protected $testingLib;

public function __construct(TestingLib $testingLib)
{
    $this->testingLib = $testingLib;
}

tykus left a reply on How To Show In Vue Tan

$(".display").hide()

You are missing the point of Vue.

You want to click on a value in PHPMyAdmin and open your browsers devtools; that is what you're asking, right???

15 Jan
2 days ago

tykus left a reply on Polymorphic Relation

Is it possible to get exact type such as $comment->video or $comment->post

That's not really the point of polymorphic relations; you don't know if the comment belongs to a Post or a Video, only that it belongs to a Commentable

09 Jan
1 week ago

tykus left a reply on Feature Test To Replicated Delete Method In Route Model Binding

The URI will be incorrect for the delete action; you are posting to admin.administrator.destroy rather than to admin/administrator/123 (where 123 would be the $this->user->id.

The correct form for the URI is admin/administrator/123, which you can get using the route helper:

route('admin.administrator.destroy', $this->user->id)

Rather than making a test postrequest, you can make a delete request:

$this->delete(route('admin.administrator.destroy', $this->user->id))
            ->assertViewIs('admin.index');
08 Jan
1 week ago

tykus left a reply on Remove Keys From Collection

What exactly are you trying to achieve @petritr - the original question wasn't as clear as I had originally understood?

The fact that there are keys on the Collection shouldn't be a concern?

tykus left a reply on Remove Keys From Collection

$collection->values()

tykus left a reply on Passing A Model Object From View To Controller

Pass? You are going to be making an HTTP request, so you are dealing with strings.

You can leverage Route-Model binding where Laravel will fetch the Model based on the id segment of the URL.

Form action:

<form action="/services/{{ $service->id }}">

Matched by route:

Route::put('services/{service}', '[email protected]');

Will fetch the model using route-model binding in the controller:

public function update(Request $request, Service $service) {
    dd($service);
}
07 Jan
1 week ago

tykus left a reply on I Want To Get Total Of Rows ..but Not Working

Prepend with @ to pass {{ }} through Blade's compiler:

@{{ logItemsCount }}
04 Jan
1 week ago

tykus left a reply on Cart

If the code does as it reads, then it is simply a method to return the items in the Cart. The only question might be what $cartItems is, e.g. Collection, object, or array

tykus left a reply on Cart

Do they...

Who knows, they do lots of things

tykus left a reply on Cart

The items in a shopping cart are retrieved using the content() method.

03 Jan
2 weeks ago

tykus left a reply on Return Items Separated Out By Date

A query builder groupBy is not appropriate here, you need to fetch all of the items and use the Collection groupBy:

$latest = Site::query()
    ->with('upvotes')
    ->where([
        ['is_approved', '=', 2],
        ['is_featured', '=', 1],
    ])->orderBy('created_at', 'DESC')
    ->get();

// $latest is a Collection
$latest->groupBy(function ($item) {
    return $item->created_at->toDateString();
});
02 Jan
2 weeks ago

tykus left a reply on Optional Request $request Function Parameter

Why not use the request() helper method instead; it gets rid of that argument, and simplifies the API?

tykus left a reply on I Get No Response From The Server After Doing This

Does Nuxt allow the asyncData function to sit in the top level of your Vue instance?

tykus left a reply on Route Model Binding Returns Empty Model

Did you mess with the web middleware group to remove the SubstituteBindings middleware?

tykus left a reply on Route Model Binding Returns Empty Model

You do not need to override the getRouteKeyName method if you are using the default id property.

Have you double-checked that the wildcard and action argument are exactly the same, i.e. product and $product respectively. If they do not match, then Route-Model binding will not work.

tykus left a reply on I Get No Response From The Server After Doing This

Surely the asyncData function should be inside either the created or mounted lifecycle hooks. I expect that the app does not make the AJAX request; check the Network tab in your browsers dev tools.

01 Jan
2 weeks ago

tykus left a reply on In Inflector.php Line 265: Syntax Error, Unexpected ':', Expecting ';' Or '{'

Laravel 5.4 requires PHP >= 5.6.4 so something is not quite adding up here.

12 Dec
1 month ago

tykus left a reply on $ Is Not Defined At.. Blade Template

Does the scripts section yield before jQuery has been loaded?

It should be in order to ensure jQuery is available, e.g.:

<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
@yield('scripts')
11 Dec
1 month ago

tykus left a reply on AssertDatabaseMissing Weird Behavior

If necessary, you can also specify which middleware(s) to remove by passing an array to withoutMiddleware, for example:

$this->withoutMiddleware([
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
]);

Obviously, you need SubstituteBindings as you have discovered.

tykus left a reply on Newly Created Record Not Appearing When Called From Relationship

Has the onboarding relation been cached on the Auth user object earlier in the request? You can get a fresh instance using:

auth()->user()->fresh()->onboarding

So the full code would be:

public function apiSend(StoreOnboarding $request)
{
    //Update the user's Onboarding details on DB
    $this->store($request);

    //Validate user's onboarding details
    $validation = $this->checkValidation(auth()->user()->fresh()->onboarding);
}

tykus left a reply on Trying To Get Property 'id' Of Non-object

Based on the code you have shared, it could be that you do not have an authenticated user, so this would fail:

Auth::user()->id

You can get the id directly from the Auth guard using Auth::id() which will return null if there is no authenticated user.

Of course, the error could be from elsewhere in your application, so look for places where you assume you have an object and are trying to get the id of that object

10 Dec
1 month ago

tykus left a reply on API In Laravel

What is the problem with making an endpoint in Project A, you need to:

  1. Define a route /api/jobs/{slug} which will respond with the result of
  2. $job = Job::findBySlugOrFail($slug);

In project B, you do the same thing...

  1. A route that will accept a slug, and in the controller
  2. make an HTTP request to Project A
  3. returning a show view with the result.
public function show($slug)
{
        $client = new \GuzzleHttp\Client();
        $request = $client->get('http://aaaa.test/api/jobs/' . $slug );
        $response = $request->getBody();
        $job = json_decode($response,true);
        return view('careers/show', compact('job'));
}

This will all feel quite slow since there are two HTTP requests needed to get the view and data.

tykus left a reply on ELOQUENT AND FOREIGN KEYS

If you define foreign key constraints on your migrations, then your database will take care of maintaining referential integrity for you (whether that means cascading deletes, or updating related records' FK's to null).

You can define a FK on a column in a migration using the following (very readable) syntax:

// migration for table X
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

So whenever you delete a user record, the related records on table X, it will cascade to all records on X that have the user's key as the user_id.

In your application code, this means that all you need to do is:

User::where('id', 123)->delete();

And every record in X where user_id is 123 will also be deleted.

tykus left a reply on ELOQUENT AND FOREIGN KEYS

how to execute foreign key and make reference back to the parent table child tables

What does that even mean?

If you want help, you need to describe the problem you are trying to solve, the steps you have taken to solve it, and the failures/errors encountered.

tykus left a reply on Laravel And Ajax

@tripletens ask better questions and you will receive better answers

tykus left a reply on API In Laravel

So there is no Job model on Project B?

If you own both projects, you either (i) add the models to Project B and query your database directly, or (ii) add an endpoint to Project A to retrieve a single Job and fetch it using Guzzle on Project B s you are already for the collection, or (iii) if you don't own A, then get the entire collection as you are in the index method and filter for the particular Job record you need.

tykus left a reply on API In Laravel

And these two projects are sharing a common models package?

tykus left a reply on API In Laravel

Is http://aaaa.test the same domain; why are you using Guzzle?

tykus left a reply on API In Laravel

How does the Job records from the http://aaaa.test/api/jobs API related to your Job model class?

tykus left a reply on API In Laravel

first view will contain all data

public function index()
{
    $jobs = Job::all();
    return response()->json($jobs);
}

second view will show only the selected data.

public function show($slug)
{
    $job = Job::findBySlugOrFail($slug);
    return response()->json($job->toArray());
}

tykus left a reply on Page Not Found

What I mean is... the order of route definitions is important. You might not be arriving at the Controller action you expected because another route was being matched first. For sanity, it is worthwhile to put a dd() at a place you expected to arrive at, to be sure you arrive there!

tykus left a reply on Vue.js - How Would I Make This In Vue.js Instead Of JQuery?

Creating a bell component, you can add a @click event listener to modify state on the component and change the classes being applied dynamically:

@foreach($rows as $row)
    <div class="row">
        {{ $row->name }}
        <bell row-id="{{ $row->id }}" @click="ringBell"></bell>
    </div>
@endforeach
Vue.component('bell', {
    template: `
        <span class="ring-bell">
            <i class="material-icons bell-icon" :class="isRinging" @click="ringBell">ring_bell</i>
        </span>
    `,
    data () {
        return {
            isShaking: false,
            this.displayModal = false
        }
    },
    methods: {
        ringBell () {
            this.isShaking = true
            this.displayModal = true
        }
    },
    computed: {
        isRinging () {
            return {
                shaking: this.isShaking,
                bg-blue: this.isShaking
            }
        }
    }
});
new Vue({
    el: '#app',
});

tykus left a reply on Disable DB Unique Checks For Tests

@devk it is worthwhile considering dedicated Factory classes to whip up related (chains) of models. This is an article from Tighten which describes the approach https://tighten.co/blog/tidy-up-your-tests-with-class-based-model-factories - I have used something similar (with some adaptations) in my own projects and it works well.

tykus left a reply on Page Not Found

Are you actually getting to the index action - if you dd(__FILE__) in that method, do you see the dd output?

Is it possible you are matching a wildcard route before you get to the admin prefix? You might need to move this group before any routes that have wildcards and might be matched before you get to the group

tykus left a reply on How To Use Constructor Inside Laravel Model

Why do you think you need a constructor in a model?

The parent expects attributes:

public function __construct(array $attributes = []) {}

tykus left a reply on Page Not Found

Not enough information to help you. Can you give us the URI you are attempting to visit; how is $this->template being used in the remainder of your controller; do you have an index action in your Controller?

You shouldn't really be using the env() helper anywhere in the application except in the config files.

tykus left a reply on Disable DB Unique Checks For Tests

It would probably be better to fix rather than patch the problem, but you probably already know this...

tykus left a reply on Get And Set Variables From Anywhere

You can define your own helper functions in the global namespace:

// app/helpers.php

<?php

if (!function_exists('context')) {
    function context()
    {
        // your implementation
    }
}

Then add to composer.json:

    "autoload": {
        "files": [
            "app/helpers.php"
        ],
    // the rest of autoloaded classes

tykus left a reply on Paginating An Array Collection In Laravel

Are you going to cache the APII response somewhere; otherwise, every page (from the paginator) will be making the same API request?

tykus left a reply on How To Run Multiple Task Automatically Using "Task Scheduling"?

You could, but wouldn't it make more sense that the controller handles HTTP requests, and is not a generic class which is being instantiated in your code?

tykus left a reply on Updating Image Using POST On Postman Dont Work

Great! Please mark the correct answer above.

tykus left a reply on Updating Image Using POST On Postman Dont Work

If you are updating by mass-assignment, then the image column must be fillable on your model

tykus left a reply on How To Run Multiple Task Automatically Using "Task Scheduling"?

Your understanding is sound, but...

I want to run automatically in background multiple tasks (some method's from a controller).

If there is logic in a Controller that is shared between regular HTTP requests and scheduled commands, then extract it to a separate class which can be used by both the Controller and the Command

09 Dec
1 month ago

tykus left a reply on Upgrade Version Of Laravel To Use Telescope

My comment was for the OP @real

tykus left a reply on Upgrade Version Of Laravel To Use Telescope

Eh? 16 > 7 since always.

Just composer require laravel/telescope

tykus left a reply on Validation In File Input

You can use the required_unless rule on all three inputs, e.g.

[
    'file1' => ['file', 'required_unless' => 'file2', 'required_unless' => 'file3'],
    'file2' => ['file', 'required_unless' => 'file1', 'required_unless' => 'file3'],
    'file3' => ['file', 'required_unless' => 'file1', 'required_unless' => 'file2'],
]

tykus left a reply on Laravel Error

Looks like you are passing an empty string to Carbon's subMinutes method:

// ...
...Carbon\Carbon->subMinutes('')
// ...