mindz

Experience

7,120

4 Best Reply Awards

  • Member Since 10 Months Ago
  • 45 Lessons Completed
  • 0 Favorites

17th November, 2017

mindz left a reply on GetAttribute In Laravel 5.5 • 6 days ago

For anyone who one day will be looking for an answer.Method getAttribute() is fired only when you call property like $model->property. If you returning collection which later is converted to array method that is used to do this is toArray() so to my Trait i had to add this method

public function toArray()
{
    $array = parent::toArray();

    foreach ($array as $key => $attribute) {
        if (in_array($key, $this->specialPropertyArray)) {
            $array[$key] = someFunction($attribute);
        }
    }
    return $array;
}

16th November, 2017

mindz left a reply on GetAttribute In Laravel 5.5 • 1 week ago

I have tried this on so many ways

  • ->relation()-first()
  • ->relation
  • ->find
  • ->where()->get()->first()

and sooo on.... and there is something wrong with it

this function works like a charm in all above ways

public function getFieldAttribute($value)
    {
        return someFunction($value);

    }
    

this never works

  public function getAttribute($key)
    {
        $value = parent::getAttribute($key);

        return someFunction($value);

    }
    

Does someone encounter this problem before?

mindz started a new conversation GetAttribute In Laravel 5.5 • 1 week ago

Is something has been changed?

in trait i created foreloquent model i can't use getAttribute($key) - it is completly . However setAttibute($key, $value)

trait SomeTrait
{
    public function getAttribute($key)
    {
            return "it just not working";
    }

    public function setAttribute($key, $value)
    {
        if (in_array($key, $this->specialPropertyArray)) {
          
            return parent::setAttribute($key, someFunctionOn($value));
        }

        return parent::setAttribute($key, $value);
    }


}

10th November, 2017

mindz left a reply on Get User In Singleton Class • 1 week ago

OK. I resolved issue

 public function methodOne($someMethod, array $parameters = [])
    {

    $parameters['headers'] [''X-Authorization'] = $auth->guard()->getUser()->getToken();

    }

Unfortunatley i don't know why it exceeds memory when i call GuardHelpers trait method. When i call directly Guard class it appear to be working

mindz started a new conversation Get User In Singleton Class • 1 week ago

Hi there. I have this issue: in my custom service provider i register an singleton

public function register()
    {
        $this->app->singleton('some-name', function ($app) {
            return new DefaultApi(env("ENV_1"), env("ENV_2"), new Client(), $app['auth']);
        });

    }

then in this class i construct singleton and it is failing on $auth->guard()->user()->getToken()

class DefaultApi implements DoesNotMatherWhat
{
    private $path;
    private $client;
    private $options;
    private $auth;

    function __construct($path, $token = null, Client $client, $auth)
    {
        $this->path = $path;
        $this->client = $client;
        $this->options = [
            'headers' => [
                'Accept' => 'application/json',
                'X-Authorization' => $auth->guard()->user()->getToken(), //here its failing with memory limit
            ]
        ];

        $this->auth = $auth;
    }

I can't pass user token to options. As for singleton it might be understandable but why i cant add it it to methodOne?

    public function methodOne($someMethod, array $parameters = [])
    {

    $parameters['headers'] = 'X-Authorization' => $auth->guard()->user()->getToken();

    }

Error i get is Allowed memory size of 268435456 bytes exhausted

Thanks in advance

27th September, 2017

mindz left a reply on Notifications Not Saved To Database • 1 month ago

provide notifications table migration please

mindz left a reply on Change Default Path For Storage Folder • 1 month ago

So in bootstrap/app.php you should do this

$app->useStoragePath( env( 'APP_STORAGE', base_path() . '/storage' ) );

mindz left a reply on How To Log Single Queries? • 1 month ago

DB::enableQueryLog();

$user = DB::table("users")->get();

$query = DB::getQueryLog();

$query = end($query);

dd($query);

mindz left a reply on Carbon Problem • 1 month ago

It cant work.

You providing object where it should be matchable string

$posts = Post::orderBy('id')
->whereDate('created_at', '>', Carbon\Carbon::now()->subMinutes(5)->toDateString()))->get();

mindz left a reply on Change Default Path For Storage Folder • 1 month ago

Or even simpler

 public function add(Request $request)
    {
        $file = $request->file('file');
        $path = $file->store('files/specific_files');           

mindz left a reply on Session Flash On L5.4 • 1 month ago

I cant recall any situation of automatic comment line of files ;) Regards

mindz left a reply on Button Component Rendering Incorrectly Inside Email • 1 month ago

Maybe you can try with slots

I dig up something like this

@component('mail::layout')
    {{-- Header --}}
    @slot('header')
        @component('mail::header', ['url' => config('app.url')])
            Header Title
        @endcomponent
    @endslot
{{-- Body --}}
    This is our main message {{ $user }}
{{-- Subcopy --}}
    @isset($subcopy)
        @slot('subcopy')
            @component('mail::subcopy')
                {{ $subcopy }}
            @endcomponent
        @endslot
    @endisset
{{-- Footer --}}
    @slot('footer')
        @component('mail::footer')
            © {{ date('Y') }} {{ config('app.name') }}. Super FOOTER!
        @endcomponent
    @endslot
@endcomponent

mindz left a reply on Session Flash On L5.4 • 1 month ago

I pasted above to first nearby project with L5.4 and it worked.

string(7) "working"

did you clean cache or somethink? What is your SESSION_DRIVER?

mindz left a reply on Getting Time Values • 1 month ago

If you want to get specyfic example you can even do 17 minutes interval if you want

$baseDate = Carbon::now();
$endDate = Carbon::now()->addDays(2); // two days from now

while($baseDate->lt($endDate)){
    echo $baseDate->format('H:i');
    $baseDate->addMinutes(17);
} 

You can do something similar in blade if you want

13th September, 2017

mindz left a reply on Swift_TransportException With Mailtrap • 2 months ago

What smtp you using?

mindz left a reply on Store Date From Datepicker Into Db • 2 months ago

Dont know what plugin you use but there is a possibility to customize format

var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' }).val();

mindz left a reply on Pass A Variable Into A Data Array To Send Email • 2 months ago

@almost_pitt

$posts = Post::all()->get(); // get() can be used on Builder object

either use

$posts = Post::all(); //returns collection

or

$posts = Post::get(); //returns collections

mindz left a reply on How To Show Old Value In Edit Blade. • 2 months ago

After submit? Or Before? Or you not submitting at all? Can't see any textfield ( i assumed you ment textfield not textfiled) in not formatted text you provided

mindz left a reply on Swift_TransportException With Mailtrap • 2 months ago

What OS you're using? You are aware you should have smpt server set up? Have you got it?

mindz left a reply on How To Show Old Value In Edit Blade. • 2 months ago

You have to write again what you want to acomplish. What is Old Value Old Value of what?

mindz left a reply on Swift_TransportException With Mailtrap • 2 months ago

provide mail.php config file from config/mail.php

mindz left a reply on When Posting Article, User_id Is 0. • 2 months ago

At first sight and obviously in my opinion you not providing user_id when you call

Article::create($request->all());

Of course my conclusion is false if you pass hidden field named user_id in your form but that is not standard approach.

You can do this in some ways.

First and simplest

 Article::create(array_merge($request->all(),['user_id'=>Auth::user()->id]));

Second

$article = Article::create($request->all());
$article->user()->associate(Auth::user())

Third via Observer

<?php

namespace App\Observers;

use App\User;

class ArticleObserver
{

    public function created(Article $article) //or saved
    {
        $article->user()->associate(Auth::user());
    }


}

mindz left a reply on Swift_TransportException With Mailtrap • 2 months ago

And you are sure that all config strings in .env are correct and not cached??

mindz left a reply on Swift_TransportException With Mailtrap • 2 months ago

Maybe you have issue with internet connection when not on vpn?

mindz left a reply on How To Show Old Value In Edit Blade. • 2 months ago

<input type="text" value="{{old('fieldName')}}" name="fieldName" />

mindz left a reply on Pusher Auth_key Error. • 2 months ago

@skoobi

I think you pass double encapsulated configs togetConfig function

In config/pusher.php you have main key in main keyed element.

So maybe instead of passing array of elements you passing array with array ?

I am no specialist of pusher but maybe this is the case.

mindz left a reply on Store Date From Datepicker Into Db • 2 months ago

@Cosmin89

$formatOfDateYouWany = Carbon::parse($request->get('datepicker')->eq(Carbon::today()))->format('yy-mm-dd')

12th September, 2017

mindz left a reply on Mail Queue - How To Handle Stacking Multiple Notifications / Messages Into 1 Email. • 2 months ago

I think i understand what You want to achieve. Therefore I would work it out in different way.

I would persist those emails data to storage with date field shouldBeSendAt . If user sends another message in application you update this storage row where email = email you want. You update field shouldBeSendAt = now()->addMinutes(3). Then you create a command executed every 1-3 minutes that check if there is anything with shouldBeSendAt in past. If there is it sending it.

With queue that you wanted to use there is a problem regarding fact that queue uses its own driver. It is definitley more complex to do it your way. In some ways impossile.

mindz left a reply on Store Date From Datepicker Into Db • 2 months ago

You must be more precise

If you want to check if datepickers date is current (i assume today)

Carbon::parse($request->get('datepicker')->eq(Carbon::today()))

mindz left a reply on Generate Dummy Data With Faker While Still Maintaining Consistent Data And Relationships • 2 months ago

If that would be the case. I would do it like that.

If you said that organization is related to purchase

$factory->define(App\Assessment::class, function (Faker $faker) {

$organizationByRandom = Organization::all()->random(); //or whatever
$relatedPurchase = organizationByRandom->purchase;

    return [
        'name' => $faker->name(),
        'email' => $faker->email(),
        'organization_id' => organizationByRandom->id
        'purchase_id' => $relatedPurchase->id
    ];
});

But remember that random is ineffective if you want to create milions of fake records. Better use randomElement on organizations ids array (pluck method)

17th June, 2017

mindz left a reply on Get Model Structure As Json • 5 months ago

Data structure is not keept in model. You have to phisically connect to database to retrive attribtutes.

In my opinion good aproach is to use some House class property (maybe) fillable or one created by yourself depending on your needs and some getter. Pack it in nice trait and use as you like.

Edit Your Profile
Update

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