cipsas

cipsas

Member Since 4 Years Ago

Vilnius

Experience Points 46,090
Experience Level 10

3,910 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 219
Lessons
Completed
Best Reply Awards 43
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.

24 Jan
5 months ago

cipsas left a reply on Query Problem -> Wrong Data

@KNUBBE82 - Sorry, then I don't understand your question

cipsas left a reply on Image Is Not Displaying In Front-end While Saving In Destination Folder

Can you check, what image path is display in frontend, which could not be found?

cipsas left a reply on Image Is Not Displaying In Front-end While Saving In Destination Folder

I think your storage folder is not public

cipsas left a reply on Query Problem -> Wrong Data

$seminars = Seminar::with([ 'meetings.users'])->with(['users' => function ($query) use ($user) {
                $query->where('id', $user->id);
            }])->get();

cipsas left a reply on Why Displays An Error Call To Undefined Method RouteNotificationFor()

Does Comment has it's email? Who should get an email when comment is added to the article? The User or the Comment?

In first case, you don't need to change User to Comment.

In second case, you have make an Comment Notifialble with trait Illuminate\Notifications\Notifiable; Then Comment table should have it's email collumn

cipsas left a reply on Passing Variable To Blade Causes Increment() To Increment DB Field Twice

If you change @include('frontend/footer', ['foo' => 'bar']), does it triple increment?

22 Jan
5 months ago

cipsas left a reply on Undefined Index: Category_id

@AAAA1111 - Which errors does it show?

cipsas left a reply on Undefined Index: Category_id

@AAAA1111 - You should define variable $filename which you try to use to set an image

cipsas left a reply on Undefined Index: Category_id

@AAAA1111 - You can use data_get() helper.

['category_id'=>data_get($data, 'category_id')]

cipsas left a reply on Caching DBqueries With Laravel?

Yes, you will have total 12 DB queries from this composer: General::all()... Post::where... Discount::where... Event::where... Modal::where... PageView::where...

x 2

You can use Debugbar package to view all DB queries: https://github.com/barryvdh/laravel-debugbar

cipsas left a reply on Trying To Get Property 'name' Of Non-object

Here you also should make the checks:

<div class="row">
        <div class="col-md-8">
            <h1>{{ $post->title }}</h1>
            <h4>{{ $post->order }}</h4>
@if($post->category)
             <h4>{{ $post->category->name }}</h4> 
@endif
            <p class="lead">{{ $post->content }}</p>
            <h4>{{ $post->status }}</h4>
        </div>

        <div class="col-md-4">
            <div class="well">

                <dl class="dl-horizontal">
                    <lable>Category:</lable>
@if($post->category)
                    <p>{{ $post->category->name }}</p>
@endif
                </dl> 

cipsas left a reply on Undefined Index: Category_id

it says, $data array doesn't have category_id. you can change it to

data_get($data, 'category_id');

cipsas left a reply on Trying To Get Property 'name' Of Non-object

So you have to make additional check:

@if($view === 'post' && $post->category)
    <td>{{ substr($post->category->name, 0, 50)}}{{ strlen($post->category->name) > 50 ? "..." : "" }}
    </td>
@endif 


cipsas left a reply on Trying To Get Property 'name' Of Non-object

Do all posts have one category?

cipsas left a reply on Define One Foreign Key Have Multiple Refrence

You can create relation through Model's like here https://laravel.com/docs/5.7/eloquent-relationships#one-to-one-polymorphic-relations

But you can't strict polymorph relation on DB side.

cipsas left a reply on Define One Foreign Key Have Multiple Refrence

You don't need these lines:

 $table->foreign('commentable_id')->references('v_id')->on('videos');
 $table->foreign('commentable_id')->references('p_id')->on('posts'); //Give Error

cipsas left a reply on This.$http Is Undefined In My Example.vue In Laravel 5.4

maybe you forget to add in may js file?

var VueResource = require('vue-resource');

Vue.use(VueResource);

cipsas left a reply on Problem In Laravel Resource

When you return resource(or collection) within controller, laravel controller under the hood resolves resource. In your case, when you try to access object or array property, resource is not resolved yet.

Here is what resolve function do:


    /**
     * Resolve the resource to an array.
     *
     * @param  \Illuminate\Http\Request|null  $request
     * @return array
     */
    public function resolve($request = null)
    {
        $data = $this->toArray(
            $request = $request ?: Container::getInstance()->make('request')
        );

        if ($data instanceof Arrayable) {
            $data = $data->toArray();
        } elseif ($data instanceof JsonSerializable) {
            $data = $data->jsonSerialize();
        }

        return $this->filter((array) $data);
    }

cipsas left a reply on Problem In Laravel Resource

If you add resolve method?

public function profile(){
        $users= (new ProfileResource(User::find(1)))->resolve();

    }

cipsas left a reply on Problem In Laravel Resource

Resource method toArray return an array, not an object

cipsas left a reply on Problem In Laravel Resource

do you try?

$user['first_name']

21 Jan
5 months ago

cipsas left a reply on Caching DBqueries With Laravel?

Of course in your case, caching the DB queries will improve performance.

And keep in mind, if you use layout, include footer, header, sidebar and etc. for each partial, compose function will be called separate. So you will have not 6 DB queries but 6x.

Good free lessons you can find here https://serversforhackers.com/laravel-perf

cipsas left a reply on Artisan Commands

in Nova/src/Console/ dir

cipsas left a reply on Photo Validation In Relationship

To avoid error in model function, you can use optional helper:

public function singlePhotoForSingleEvent() {
        return optional($this->photos())->first();
    }

in view you should also check if the image exist, because it will show "no image" and also throw error because try to access filename property of null

17 Jan
5 months ago

cipsas left a reply on Multiple Form Update

It is good practice to separate those forms. Good talk about it: https://youtu.be/MF0jFKvS4SI?t=51

cipsas left a reply on Multiple Form Update

I think it would be better to have separate url address, where you submit each form with separate controllers.

Route::put('basic', '[email protected]');

Route::put('legal', '[email protected]');
...

and in template:

<form action="/basic">
...
</form>

<form action="/legal">
...
</form>
21 Jul
11 months ago

cipsas left a reply on Eager Loading Doesn't Work

@Cronix when I remove those lines, number of queries are the same. I think Eloquent is smart enough to skip duplicated queries. But yes, those lines are unnecessary. Thanks for the tip

cipsas left a reply on Eager Loading Doesn't Work

I figured it out. Product model has mutator, which loads 'type' relation. So I guess, when in controller I call to load 'type.categoryTypes', laravel checks that 'type' relation is already loaded and skip it. @Snapey thanks for hint

cipsas started a new conversation Eager Loading Doesn't Work

In my controller I try to load relations like this:

        $product->load(
            'variants',
            'variants.product',
            'type',
            'type.categoryTypes',
            'type.attributes',
            'type.attributes.attributeValues'
         );

        return $product;

All relations are loaded except categoryTypes. But when I return

return $product->type;

it loads. What cause this behaviour? Why 'type.categoryTypes' isn't loaded when return $product?

27 Mar
1 year ago

cipsas left a reply on View Composer Using Singleton

I thought about caching. But 'singleton' approach looked more cleaner. But thinking about View::composer() logic, it seems to impossible make it work with singleton

cipsas started a new conversation View Composer Using Singleton

Hi,

I am need to share variables in multiple views. And to make fewer queries to DB, try to use singleton.

<?php

namespace App\Providers;

use Illuminate\View\View;

class AppServiceProvider extends ServiceProvider
{
public function boot()
    {
        View::composer('*', 'App\Http\Composers\ViewComposer');
    }

public function register()
    {
            $this->app->singleton(  'App\Http\Composers\ViewComposer' );
    }

}

But when debug in ViewComposer file, compose method( and queries in that method) are called as many times, as view templates are loaded( main template with layout and other partials). I try to do by this example https://sasablagojevic.com/sharing-data-between-views-in-laravel but it doesn't work. What I'm doing wrong?

06 Feb
1 year ago

cipsas left a reply on Specifying Columns For Eager-loaded Relationships

Strange.. Looks everything ok. If change collumns, i.e 'posts:id,body', is the same?

cipsas left a reply on Specifying Columns For Eager-loaded Relationships

can you show DB structure? column names?

cipsas left a reply on What's The Best Way For Create Link In Laravel With "_blank" Attribute?

First need to check if file url is correct and meets apps public path folders. Is really this file exist. Also perrmissions

cipsas left a reply on Specifying Columns For Eager-loaded Relationships

Try this, is different result or same?

public function getThreads(Forum $forum)
{
    $threads = Thread::latest('updated_at')
        ->with( 'author:id,username')
        ->with('forum:id,name,ic')
    ->with( 'posts:id,created_at');
    

    if ( $forum->exists ) {
        $threads->where('forum_id', $forum->id);
    }

    return $threads->paginate(5);
}

cipsas left a reply on How Do You Break Out Of A Collection Pipeline Early?

Maybe this idea will help:

$filters = [
            [ 
                'option' => 'make', 
                'value' => 'toyota'
            ],
            [ 
                'option' => 'model', 
                'value' => 'prius'
            ],
            ....
        ];
$filtered = collect($items);
$counter = 0;

while ($filtered->count() > 1) {
    $filtered->where($filters[$counter]['option'], $filters[$counter]['value']);
    $counter++;
}


07 Aug
1 year ago

cipsas left a reply on Vue Select Get Request Help

To create new category and update:

methods: {
    updateOptions() {
            loading(true)
            axios.post('api/v1/categories', this.options)
                .then(response => {
               
                loading(false)
            }) 
    .catch(function (error) {
            console.log(error);
    });
  }

...
}

And don't forget to add csrf value to axios header:

axios.defaults.headers.common['X-CSRF-TOKEN'] = // YOUR CSRF TOKEN;

cipsas left a reply on Vue Select Get Request Help

Default options value set to empty array, not to null. It's important:

data() {
            return {
                options: []
            }
        },

cipsas left a reply on Vue Select Get Request Help

To narrow down case, do you debug is server side return correct data?

25 Jul
1 year ago

cipsas left a reply on Check If Active

Maybe:

...
<ul class="navbar-nav mr-auto">
  @foreach($navPages as $pages)
    <li class="nav-item @if($pages->slug == request()->route('slug') ) active @endif">
      <a class="nav-link" href="{{ url($pages->slug) }}">{{ $pages->title }}</a>
    </li>
   @endforeach
</ul>
...
10 Jul
1 year ago

cipsas left a reply on Collection Properties To Json.

You need to use method push in this case:

$collection = collect([]);
$collection->push(['name' => 'C One']);

When you initiate $collection = collect([]);, $collection is object. When you call $collection->name = 'C One' you just add property to object, not items. To get the idea, try:

        $collection = collect([]);
        $collection->name = 'C One';
    $collection->push(['name' => 'C Two']);

        dd($collection);
09 Jul
1 year ago

cipsas left a reply on How To Reduce Amount Of Queries

Perhaps you can query all vehicles and then do the check?

$transport = Transport::with('car', 'bike', 'van')->get(); 

// Then do the checks 
if(...){
...
}
08 Jul
1 year ago

cipsas left a reply on Call Laravel Controller From Code And Pass HTTP Headers To It

Maybe this works:

$response =  (new $controllerName)->methodName();
05 Jul
1 year ago

cipsas left a reply on CORS

Because CORS is so easy, nobody would watch it :)

29 Jun
1 year ago

cipsas left a reply on How Can I Share Laravel Folder In Other Computers

Register https://www.dropbox.com/?landing=cntl download app, select folder you want to share. And then install this app in all other computers you want to share. Then this folder will be sync with all computers

cipsas left a reply on How Can I Share Laravel Folder In Other Computers

You can use dropbox or google disk for this purpose

cipsas left a reply on Issue While Delete Record In Laravel 5.4 Using Ajax Request?

Try fix route - you two times use skilset in delete route - one in group prefix, second in route. Try to change:

Route::delete('/delete/{id}', ['uses' => $namespacePrefix .   '[email protected]', 'as' => 'destroy']);