Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

tykus

Full Stack PHP Developer at FordeCloud

Experience

389,960

612 Best Reply Awards

  • Member Since 3 Years Ago
  • 1190 Lessons Completed
  • 0 Favorites

13th December, 2017

tykus left a reply on Undefined Property: Illuminate\Database\Eloquent\Collection::$item • 4 hours ago

If you are trying to display all photos for each flyer, then you can use a nested loop (also a good idea to eager-load the photos relationship):

$flyers = Flyer::with('photos')->where('user_id', '=', $user->id)->get(); 
@foreach($flyers as $flyer)
    {{ $flyer->name }}
    @foreach($flyer->photos as $photo)
        {{ $photo->thumbnail_path }}
    @endforeach
@endforeach

tykus left a reply on Model Factory Is Generating Empty Objects • 4 hours ago

What is $product->name returning; null?

tykus left a reply on Model Factory Is Generating Empty Objects • 5 hours ago

You misunderstood; this wasn't assignment $product->name // == 'someInput' ?? - I meant for you to check if the name property was set by the factory.

tykus left a reply on Model Factory Is Generating Empty Objects • 5 hours ago

Yeah, worth a shot... am pretty sure Eloquent is unguarded anyway when you use a factory... can't remember exactly.

Is the name property hidden?

tykus left a reply on Model Factory Is Generating Empty Objects • 5 hours ago

Mass-assignment protection?

12th December, 2017

tykus left a reply on Is There A Nice Way To Handle Empty Dates In Templates? • 1 day ago

If you are using Laravel 5.5, you should be able to use the optional() helper method for objects (some_date_field being a Carbon instance in the following):

{{ optional($record->some_date_field)->format('d.m.Y') }}

In the case of complete_till you do not have an object at all, so the check probably belongs in the getCompleteTillCarbonAttribute method instead.

tykus left a reply on Database Queries • 1 day ago

You can inline your query, but why would you want to; what do you think benefits you to do this?

tykus left a reply on Implement Sweet Alert Delete • 1 day ago

Adapted from the SweetAlert docs:

swal({
    title: "Are you sure?",
    text: "Once deleted, you will not be able to recover this!",
    icon: "warning",
    buttons: true,
    dangerMode: true,
})
.then((willDelete) => {
    if (willDelete) {
        axios.delete('/path/to/delete/resource')
            .then((response) =>  {
                swal("Deleted successfully!", {
                        icon: "success",
                    });
            })
            .catch(() => {
                swal("Error!", "Failed to delete!", "error");
            })
    }
})

tykus left a reply on Auth User In Query, Is This Also Good Practise? • 1 day ago

Typically, I would use a relationship in similar cases:

auth()->user()->workerTests;

But it amounts to the same thing really. The route(s) that use this Controller method would be protected by auth middleware of course.

Also, you can get the id for the authenticated user using Auth::id() or auth()->id() which looks a little cleaner to my eye.

11th December, 2017

tykus left a reply on I Can't Migrate My Migrations • 1 day ago

Change DB_HOST=localhost to DB_HOST=127.0.0.1

9th December, 2017

tykus left a reply on Sync Hasmany • 3 days ago

It'd be more efficient to do this in two queries:

(i) Remove all Player associations with the current Team:

$this->players()->update(['team_id' => null]);

(ii) Reassociate the Players matching the given ids:

Player::whereIn('id', $newIds)->update(['team_id' => $this->id]);

tykus left a reply on Delete From Database • 3 days ago

Does this User_liens::where('chance', true)->get() get any results?

Also, be careful with this DB::table('users')->delete();!!

tykus left a reply on Remove Unwanted Text From Database • 3 days ago

You probably want the HTML tags in the database to properly render the HTML body, but you can use the native strip_tags function to get rid of the tags

http://php.net/manual/en/function.strip-tags.php

tykus left a reply on Trying To Display Image But Still Failed • 4 days ago

You might have a problem that you are defining a relative path rather than an absolute path. Try adding a leading forward slash / to the path:

<img src="/images/homestay/{{$homestay->foto_1}}">

8th December, 2017

tykus left a reply on General Doubts On Standard Login Blade Template Generated By Laravel • 4 days ago

Because password is required, which is a separate error.

If the user removes the required attribute on the password field, then you can get a password required validation error.

tykus left a reply on General Doubts On Standard Login Blade Template Generated By Laravel • 4 days ago

If the user removes the required attribute on the password field, then you can get a password required validation error.

Otherwise, under normal circumstances, you do not want to expose the fact that an email address is valid (but password failed) on your site, so all auth errors are generalized.

tykus left a reply on Getting The Total Of Payments By Row • 4 days ago

If you are only interested in the current month, then a GROUP BY is not required:

$sum = Model::whereMonth('created_at', '=', date('m'))->sum('payments');

tykus left a reply on I Cannot Compile Laravel's Assets • 4 days ago

Please try running this command again as root/Administrator.

You don't have the correct permissions for some reason. I'd start there

tykus left a reply on How To Query This • 5 days ago

Given this a try instead:

 $districts = District::with([
    'cases' => function ($query) {
            $query->whereMonth('crime_date', date('m')) 
                    ->whereYear('crime_date', date('y'));
        },
    'cases.crime'
])->get();

tykus left a reply on Vue Router On History Mode Static Assets Won't Load. • 5 days ago

You appear to have used relative URLs when defining your asset paths; the browser attempts to fetch the asset in the context of the current URL. You need to prepend a / so that the browser attempts to fetch the asset from the context of the root.

https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL#Absolute_URLs_vs_relative_URLs

tykus left a reply on How To Query This • 5 days ago

You are not showing relationships on any of your models, e.g.

_a district has many cases

public function cases()
{
    return $this->hasMany(Case::class)
}

a case belongs to a crime

public function crime()
{
    return $this->belongsTo(Crime::class)
}

In the controller, you can eager load the cases and crimes with the districts:

public function index(){
    $districts = District::with(['case.crime' => function ($query) {
        $query->whereMonth('crime_date', date('m')) 
            ->whereYear('crime_date', date('y'));
    }])->get();

        return view('case.report', compact('districts'));
}

// view template

@foreach($districts as $district)
    <tr>
        <td>{{ $district->name }}</td>
        <td>{{ $district->cases->count() }}</td>
        <td>
            @foreach($district->cases as $case)
                {{ $case->crime->name }} <br>
            @endforeach     
        </td>
    </tr>
@endforeach 

tykus left a reply on Chaining Traits • 5 days ago

Are Global Scopes the right approach here? A local scope could be defined in a trait if you wanted to mix it into different Models.

tykus left a reply on Route [login] Not Defined. • 5 days ago

Do you have either of the following in your web route?

Auth::routes();

or

Route::get('login', 'Auth\LoginController')->name('login');

Your post/create route is protected by auth middleware, which redirects to a route named login if a Guest tries to POST to there.

7th December, 2017

tykus left a reply on Method Not Allowed Error • 5 days ago

work.step?

tykus left a reply on Share Database Data To All Views From AppServiceProvider • 5 days ago

You can have Laravel check if the tables exist first, e.g.

if (Schema::hasTable('domains')) {
    $domains = Domain::get();
}

if (Schema::hasTable('domains')) {
    $regions = Region::get();
}

if (isset($domains) && isset($regions)) {
    View::composer('*', function($view) use($domains, $regions){`
        $view->with('domains', $domains);
        $view->with('regions', $regions);
    });
}

Obviously you need to

tykus left a reply on Eloquent Query In Laravel 5.5 • 6 days ago

Did you try this:

If you want 0 as the value for mr_role_id then the SQL syntax should be SELECT 0 AS mr_role_id instead of SELECT mr_role_id AS 0

tykus left a reply on Disable Blade View Button From Controller • 6 days ago

Several possibilities https://laravel.com/docs/5.5/views#passing-data-to-views

return view('view.name')->with('disableButton', false);

or

return view('view.name', ['disableButton' => false]);

or

$disableButton = false; // or whatever logic determines this...

return view('view.name', compact('disableButton'));

tykus left a reply on Laravel Relationship With Custom Table And Custom Column Name • 6 days ago

Eloquent relationships are on Eloquent models, not on query builder results.

$numbers = ElectoralList ::where('town_id', Auth::user()->town_id)
        ->where('number', $term)
        ->first();

tykus left a reply on Post To Controller From A Form Action • 6 days ago

You have no route defined for that action:

Route::post('AddresseeList', '[email protected]');

tykus left a reply on Post To Controller From A Form Action • 6 days ago

You need to show us your Blade template, relevant route(s) and Controller.

tykus left a reply on Matwebsite Export To Using Blade • 6 days ago

Move the export method:

Excel::create('New file', function($excel) use($data) {
    $excel->sheet('New Sheet', function($sheet) use ($data) {
        $sheet->loadView('admin.pages.export_ledger_entry_report',array('data' => $data));
    })
})->export('xls');

6th December, 2017

tykus left a reply on VueRouter To A Laravel Login Blade Page? • 6 days ago

Why do you need Vue Router; use a normal anchor tag for a regular link <a href="/login"> or window.location = 'login'; to redirect programmatically.

tykus left a reply on Get Image Source • 1 week ago

Use the e.getAttribute('src') instead of e.src

tykus left a reply on Get Image Source • 1 week ago

Show your javascript selectImage1() method

tykus left a reply on Get Image Source • 1 week ago

You can't use <img> as a form element.

I assume your JS is dynamically setting the src attribute on the <img> tag? Just use than same JS to set a value on a hidden <input> element inside your form:

 <img id="inside_image"  src=""/>
<input type="hidden" name="inside_image" value="" /> 

 <div class="form__group--img">
   <span class="photos_upload_span ion-upload"></span>
   <div class="author_photos_upload  photos__add__input" onclick="selectImage1(this)"></div>

tykus left a reply on Get Image Source • 1 week ago

I don' get it... is this supposed to be sent as request data?

<img name="inside_image" id="inside_image"  src=""/>

tykus left a reply on Laravel 5.5 On Synology NAS • 1 week ago

I am not in a position to test on my own NAS right now, but I believe you can use the PHP7 cli using php70 or php71 instead of php, e.g.

php70 artisan migrate

If you wish composer to use a specific php version, then you would need

php70 path/to/composer install

You can get the path from which composer

tykus left a reply on Month Changing • 1 week ago

Carbon has several handy methods for adding and subtracting time:

$dueDate = '12/5/2018';
$newDueDate = Carbon::parse($dueDate)->addMonth();

tykus left a reply on Class 'Collective\Html\HtmlServiceProvider' Not Found • 1 week ago

You followed the Upgrade Guide, right?

tykus left a reply on Class 'Collective\Html\HtmlServiceProvider' Not Found • 1 week ago

Yes, if you run composer update, what output do you get?

tykus left a reply on Class 'Collective\Html\HtmlServiceProvider' Not Found • 1 week ago

This:

Laravel Framework 5.4.36

and this:

"laravel/framework": "5.5.*",

are clearly out of sync... how did you come to have "laravel/framework": "5.5.*", in your composer.json file

tykus left a reply on Eloquent Query In Laravel 5.5 • 1 week ago

If you want 0 as the value for mr_role_id then the SQL syntax should be

SELECT 0 AS mr_role_id ...

not

SELECT mr_role_id AS 0 ...

tykus left a reply on BadMethodCallException: Call To Undefined Method Illuminate\Database\Query\Builder::post() In File • 1 week ago

You are instantiating the wrong Client - it should be the Guzzle Client, not the Passport client.

use GuzzleHttp\Client as GuzzleClient;

$http = new GuzzleClient;

tykus left a reply on Eloquent Query In Laravel 5.5 • 1 week ago

'rbac_roles.mr_role_id as 0'

tykus left a reply on Class 'Collective\Html\HtmlServiceProvider' Not Found • 1 week ago

The output you got suggests that you are not using Laravel 5.5; what do you get when you run

$ php artisan --version

tykus left a reply on Eloquent Query In Laravel 5.5 • 1 week ago

Your problem is you have aliased mr_role_id AS 0

tykus left a reply on Laravel With Vue • 1 week ago

No worries; good luck with it!

tykus left a reply on Laravel With Vue • 1 week ago

Okay, that is not broadcasting...

What you can do is get the NotificationList component to check for new notifications every n seconds:

mounted () {
    setInterval(() => {
        axios.get('/notifications/list').then(response => {
            // JSON responses are automatically parsed.
            this.notifications = response.data
        }).catch(e => {
            this.errors.push(e)
        })

    }, 30000); // 30 seconds
}

tykus left a reply on Class 'Collective\Html\HtmlServiceProvider' Not Found • 1 week ago

Correct. If you run composer update on a Laravel 5.5 app, you should see something similar to the following at the end of the output:

> @php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: laravelcollective/html

This means that Laravel has registered the package itself.

tykus left a reply on Laravel With Vue • 1 week ago

Not sure TBH, I don't use anything Broadcasting related.

How were you listening for the broadcast previously? You have a number of options for storing the notifications, e.g. you can put them on the window object (under some namespace so the global namespace isn't poluted).

Edit Your Profile
Update

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