tykus

Full Stack PHP Developer at FordeCloud

Experience

471,570

738 Best Reply Awards

  • Member Since 3 Years Ago
  • 1230 Lessons Completed
  • 1 Favorite

24th February, 2018

tykus left a reply on Intervention Image Orientation Taken By IPhone • 1 day ago

I had a similar issue, and gave up trying to rely on EXIF; instead I just interrogated the image myself:

if ($image->width() > $image->height()) {
    $image->rotate(90);
}

23rd February, 2018

tykus left a reply on I Need To Get Episodea By Id Like Animes • 1 day ago

Just because it's convention doesn't mean it is followed ;-)

tykus left a reply on I Need To Get Episodea By Id Like Animes • 1 day ago

should be capital Anime, or App\Anime

This assumes that the class is named with a capital A @Cronix

tykus left a reply on Accessing Environment Variable In My Custom Class • 1 day ago

Where do you have this in your custom class?

private $API_KEY = env("MSG91_KEY");

tykus left a reply on 'Method WhereBetween Does Not Exist' When Using Cached Query. • 1 day ago

You have a collection rather than a Builder instance; there is no whereBetween method available on Collection.

tykus left a reply on __construct On Child Model • 2 days ago

Usually it is under the avatar, beside the like icon

tykus left a reply on Laravel Append Attribute Not Working • 2 days ago

That looks like the Product instance's attributes array, not an array representation of a Product instance! There is a difference!

If you are working with a Product object, then you can get the accessor attributes using $product->my_rating and $product->average_rating.

If you want the array or json representation of the Product object, then return it as an array/json $product->toArray() or $product->toJson() - now accessors included in the $appends array will automatically be included.

tykus left a reply on I Need To Get Episodea By Id Like Animes • 2 days ago

I am wondering why you are getting a fresh instance rather than a ModelNotFoundException... can you check that the wildcard name {episode} matches the argument name in the controller method signature $episode?

tykus left a reply on Laravel Append Attribute Not Working • 2 days ago

@borisu the attribute names are typically referenced in snake_case while the accessor is camelCase

@ajitdas how are you getting the json/array representation of the Product(s) in the controller?

tykus left a reply on Using Event On Vue Component To Trigger Update On Another. • 2 days ago

You can create a global event bus using an empty Vue instance, which will allow you to communicate between components which are not in a parent/child relationship:

// booststrap.js

let window.EventBus = new Vue();

You could optionally pass the new message in the event:

// modal component

<messages-create-modal @created="EventBus.$emit('created', message)"></messages-create-modal>
// messages list component
 
EventBus.$on('created', message => {
  this.messages.push message
});

tykus left a reply on Route Help • 2 days ago

No. Not possible.

22nd February, 2018

tykus left a reply on My Relationships Are Remembered. • 2 days ago

Is this in a single request/response cycle - can you get the desired result from $selectedUserGroup->fresh()->agreements;?

Or, are you caching somewhere?

tykus left a reply on I Need To Get Episodea By Id Like Animes • 2 days ago

Actually, I just see now in the screenshot it has exists: false, so you are not getting an existing instance. Effectively, you are using a new Episode instance.

tykus left a reply on I Need To Get Episodea By Id Like Animes • 2 days ago

So, you have a view resources/views/watch.blade.php; is it displaying in the browser? Are you able to use the $episode in your view template, e.g. {{ $episode->toJson }}

tykus left a reply on I Need To Get Episodea By Id Like Animes • 2 days ago

Can you dd($episode) inside the controller method to see if (i) you are getting as far as that method and (ii) you are getting anything from route model binding?

tykus left a reply on I Need To Get Episodea By Id Like Animes • 2 days ago

Oh my Gawd!

What is not working? Are you getting an error? What URI are you requesting?

tykus left a reply on I Need To Get Episodea By Id Like Animes • 2 days ago

Since you do not use anime in the controller method, I think it is better to remove that parameter and leave the URI as animes/episodes/{episode}:

public function Episodes(episode $episodes)
{
    return view('watch', compact('episodes'));
}

tykus left a reply on I Need To Get Episodea By Id Like Animes • 2 days ago

When I suggested to change the route definition, it was either that or change the method signature, not both

tykus left a reply on Pass Variable Into Function • 3 days ago

Not Working ?

Very difficult to help if that's all you are asking... what is not working; what have you tried?

tykus left a reply on Laravel Blade Files Blink And Then Blank • 3 days ago

Any errors in the browser's console?

tykus left a reply on Pass Variable Into Function • 3 days ago

So this route definition contains two wildcards anime and episode, but your controller action is expecting just one, so change it to either accept both arguments:

public function Episodes(anime $anime, episode $episodes)
{

    return view('watch', compact('episodes'));
}

or, since you are not using the anime variable in the controller, change the route definition:

Route::get('animes/episodes/{episode}', '[email protected]');

tykus left a reply on Pass Variable Into Function • 3 days ago

What's up?

tykus left a reply on Pass Variable Into Function • 3 days ago

Just chain orderBy(fieldname, [direction]) to the Eloquent query:

$episodes = Episode::where('anime_id', '=', $anime->id)->orderBy('fieldname')->paginate(1);

tykus left a reply on Laravel 5.3 Throws 500 Error Formrequest • 3 days ago

Surely there is something in your storage/logs/laravel.log which gives more detail about the error?

tykus left a reply on Pass Variable Into Function • 3 days ago

And what is preventing you doing what you want; is $anime a model instance?

$episodes = Episode::where('anime_id', '=', $anime->id)->paginate(1);

tykus left a reply on Pass Variable Into Function • 3 days ago

Are you route-model binding here? What is the issue?

tykus left a reply on Laravel 5.5 Get All Records Which Has Same And Latest 'updated_at' Column Value. • 3 days ago

\DB::raw("(select max(updated_at) from orders where kitchen_status = 1

This will do what you need, but probably could be optimisted up further.

tykus left a reply on Automatically Pass Data To Views • 3 days ago

I don't think the OP is talking about view composers, but rather passing all data in the controller action's scope into the view that is being returned. My immediate thought was to use get_defined_vars(), but I would be wary about blindly passing everything that give you.

21st February, 2018

tykus left a reply on Conditional Middleware • 3 days ago

Why middleware, and not the authorization system built into Laravel such as Gates and Policies??

tykus left a reply on Self Join In Eloquent Model • 3 days ago

// Category.php

public function chilrden()
{
    return $this->hasMany(Category::class, 'parent_id');
}

public function parent()
{
    return $this->belongsTo(Category::class, 'parent_id');
}

tykus left a reply on __construct On Child Model • 4 days ago

Great @BSP, mark is solved to help others.

20th February, 2018

tykus left a reply on Merging A Collection Of Two Models? • 4 days ago

Well, it is $model and not $user.

This is the reason I suggested the polymorphic approach...

tykus left a reply on Merging A Collection Of Two Models? • 4 days ago

@Snapey 4/2000 - if it was a nag, I wouldn't back it ;-)

@splendidkeen PHP sucks sometimes - this is a known issue. Use a String instead:

@if($model instanceof 'App\Business')

tykus left a reply on Merging A Collection Of Two Models? • 4 days ago

@Snapey did you try it? I have always assumed my understanding was correct because of the implementation of merge on the Eloquent Collection class:

    /**
     * Merge the collection with the given items.
     *
     * @param  \ArrayAccess|array  $items
     * @return static
     */
    public function merge($items)
    {
        $dictionary = $this->getDictionary();
        foreach ($items as $item) {
            $dictionary[$item->getKey()] = $item;
        }
        return new static(array_values($dictionary));
    }

Here $dictionary[$item->getKey()] = $item; the model's key (usually id) will decide what gets into the dictionary. If the key has already been assigned, then it will be overwritten.

tykus left a reply on Merging A Collection Of Two Models? • 4 days ago

You could @include a partial based on the class name which would require you to :

@foreach($collection as $model)
    @include('partials.' . class_basename($model));  // partials.Model1 or partials.Model2
@endforeach

tykus left a reply on Merging A Collection Of Two Models? • 4 days ago

No need to convert anything.

Are you sure @Snapey - I have tried it and it will only work as expected when different model ids are returned in each Eloquent Collection

tykus left a reply on Merging A Collection Of Two Models? • 4 days ago

When you want to merge Eloquent collections, you need to first convert them to Base Collections using the toBase() method - this prevents overwriting existing items when ids collide. Next, you need to decide if you are happy to have 0 - 4 possible instances of Model1 and 4 - 0 instances of Model2, or if you want 2 of each as this will determine how the collection should be composed:

// random 2 items from each Model
$model1s = Model1::inRandomOrder()->take(2)->get();
$model2s = Model2::inRandomOrder()->take(2)->get();
$collection = $model1s->merge($model2s);

// random 4 from combined collection (note this loads _all_ records into PHP!)
$model1s = Model1::all();
$model2s = Model2::all();
$collection = $model1s->merge($model2s)->random(4);

tykus left a reply on __construct On Child Model • 4 days ago

Why not define a relationship between the Profile and File models? You would access the File instance using the relationship:

$user->profile->file;
// Profile.php

public function file()
{
    return $this->hasOne(File::class, 'uid'); // non-conventional foreign key must be explicit 
}

tykus left a reply on Error While Saving Users Data • 4 days ago

You are not passing the name input to the create method

User::create(request(['username', 'email', 'password', 'name']));

tykus left a reply on Use Function Parameter In Join Closure • 4 days ago

$data = DB::table('users')
->join('need', function($join) use ($id) {   
    $join->on('users.id', '=', 'need.user_id')
        ->where('need.id', '=', $id);
})
->get();

tykus left a reply on Excluding If Same Id And Done = 0. • 4 days ago

The result you expect is no consistent with the data you have provided and constraints you describe. Why would Rolf be excluded given he has visits which are _'done'_?

http://sqlfiddle.com/#!9/27421/3

tykus left a reply on Laravel - Intervention Image - Can't Write Image Data To Path • 5 days ago

And... you don't think that's a problem?

tykus left a reply on Laravel - Intervention Image - Can't Write Image Data To Path • 5 days ago

Where is that space coming from in the path?

/var/www/parti/storage/uploads/session message-1519133083.png
                                      ^

tykus left a reply on What Is The Use Of Console Folder In The Laravel ? • 5 days ago

Your custom Artisan commands

tykus left a reply on Bcrypt Giving Different Value When User Changes Password • 5 days ago

This is expected behaviour; bcrypt doesn't generate the same hash for the same string by design. With regard to the failure to login, I would check if you are double encrypting

Aside, this grates...

$user=User::find(auth()->user()->id); 

Why would you need another query?

return view('profile')->with('user', auth()->user());

tykus left a reply on Trying To Get Property Of Non-object • 5 days ago

Why not define a relationship between the Product and Attribute models, eager-load the attribute whenever getting the Products, then there is no reason to check if $attribute->id == $products->attribute_id since they already have established their link?

tykus left a reply on Trying To Get Property Of Non-object • 5 days ago

but it fetches all the attributes_1 value

And this wrong? I don't know exactly what you are trying to do, so...

tykus left a reply on Trying To Get Property Of Non-object • 5 days ago

Well, if you need Product objects, you could do this:

public function category()
{
    $products =  \App\Product::get();

    $subids = $products->pluck('attribute_id');
             
    $attributes =  \App\Attribute::whereIn('id', $subid)->get();
                     
    return view('category', compact('attributes', 'products'));
}
@foreach($products as $product)
    @foreach($attributes as $attribute)
        @if($attribute->id  == $products->attribute_id)
            {{$attribute->attribute_1 }} <input  type="checkbox">
        @endif
    @endforeach
@endforeach

Meaningful variable names really help with understanding your code!

tykus left a reply on Trying To Get Property Of Non-object • 5 days ago

This $subids->attribute_id is the problem. $subid is an array of integers (presumably), not Product instances

19th February, 2018

tykus left a reply on Laravel 5.6 Cache::rememberForever Not Caching Data With Variable Key • 5 days ago

Does, or can your key have a space; is $id an integer or a string?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.