Sergiu17

Sergiu17

Member Since 2 Years Ago

Chisinau

Experience Points
325,260
Total
Experience

0 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
1554
Lessons
Completed
Best Reply Awards
260
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 50
325,260 XP
Jan
28
11 hours ago
Activity icon

Replied to Need Suggestions

Amazon from scratch with Laravel & VueJS

Jan
26
2 days ago
Activity icon

Awarded Best Reply on Editable Table But Save All Values

@theunforgiven this is what I'd probably do

@foreach($costItems as $key => $cost)
    <td contentEditable="true" class="edit" id="q1_{{ $key }}"></td>
@endforeach

<button>Save</button>

<script>
    const itemsToBeSubmitted = []; // store here edited items

    $(".edit").focusout(function(){
        let split_id = this.id.split('_');
        let field_name = split_id[0];
        let edit_id = split_id[1];
        let value = $(this).text();

        itemsToBeSubmitted.push({
            field: field_name,
            value: value,
            id: edit_id
        });
    });

    // Now you have an array all edited elements
    document.querySelector('button').addEventListener('click', function() {
        $.ajax({
            url: '/claim/store',
            type: 'post',
            data: itemsToBeSubmitted,  // edited items
            success: (response) => {
                console.log('Saved successfully');
            }
        });
    });

PHP part

public function store(Request $request)
{
    $request->all(); // this is an array of arrays
    
    foreach($request->all() as $item)
    {
        // $item['id'], $item['field'], $item['value'];
        $model = Model::find($item['id'];
        
        $model->{$item['field']} = $item['value'];

        $model->save();
    }

    return 'Done';
}

I didn't tested this code, but I created something similar before. Hope it helps

Activity icon

Replied to Editable Table But Save All Values

@theunforgiven this is what I'd probably do

@foreach($costItems as $key => $cost)
    <td contentEditable="true" class="edit" id="q1_{{ $key }}"></td>
@endforeach

<button>Save</button>

<script>
    const itemsToBeSubmitted = []; // store here edited items

    $(".edit").focusout(function(){
        let split_id = this.id.split('_');
        let field_name = split_id[0];
        let edit_id = split_id[1];
        let value = $(this).text();

        itemsToBeSubmitted.push({
            field: field_name,
            value: value,
            id: edit_id
        });
    });

    // Now you have an array all edited elements
    document.querySelector('button').addEventListener('click', function() {
        $.ajax({
            url: '/claim/store',
            type: 'post',
            data: itemsToBeSubmitted,  // edited items
            success: (response) => {
                console.log('Saved successfully');
            }
        });
    });

PHP part

public function store(Request $request)
{
    $request->all(); // this is an array of arrays
    
    foreach($request->all() as $item)
    {
        // $item['id'], $item['field'], $item['value'];
        $model = Model::find($item['id'];
        
        $model->{$item['field']} = $item['value'];

        $model->save();
    }

    return 'Done';
}

I didn't tested this code, but I created something similar before. Hope it helps

Activity icon

Awarded Best Reply on File_put_contents In Framework/views Failed To Open Stream: No Such File Or Directory

You probably don't have permissions, try with chmod or chown

cd /var/www/project
ll // to see current permissions to storage folder
chmod -R 775 storage
Jan
23
5 days ago
Activity icon

Replied to Mock In Feature Test

Hi, show us the method which is triggered when you submit the post request

Jan
22
6 days ago
Activity icon

Replied to How To Fetch Login User And Insert Details To Login User

{{ auth()->user()->name }}

make sure this view is under auth middleware

Activity icon

Awarded Best Reply on Delete Model With All Relations

@karolgil

$model->relation()->delete();

$article = Article::find(1);
$article->comments()->delete();

Also, consider what @codebyray said, will work much faster, with less code )

Activity icon

Replied to Delete Model With All Relations

@karolgil

$model->relation()->delete();

$article = Article::find(1);
$article->comments()->delete();

Also, consider what @codebyray said, will work much faster, with less code )

Jan
20
1 week ago
Activity icon

Replied to (PHP) - Find Key Value In An Associative Array

@dk4210

foreach($array['data'] as $user)
{
    if($user['name'] === 'bob') {
        echo $user['clientOid'], ' ', $user['schema'], ' ', $user['createdBy'];
    }
}
Activity icon

Replied to (PHP) - Find Key Value In An Associative Array

Like so

foreach($array['data'] as $user)
{
    if($user['name'] === 'bob') {
        print_r($user);
    }
}
Activity icon

Awarded Best Reply on (PHP) - Find Key Value In An Associative Array

$array['data'][0]['name']; // this should give you the name
Activity icon

Replied to (PHP) - Find Key Value In An Associative Array

$array['data'][0]['name']; // this should give you the name
Jan
18
1 week ago
Activity icon

Awarded Best Reply on Having Trouble With Relationship/collection ..

@bmartus limit() returns Query and of course there's no user on the Query class

return $this->comments()->latest()->first(); // change to first.

hope this will be last issue. Also, you need to add an if statement to check if there is at least on comment, then print it, otherwise you will get trying to get property of non object

Activity icon

Replied to Having Trouble With Relationship/collection ..

@bmartus limit() returns Query and of course there's no user on the Query class

return $this->comments()->latest()->first(); // change to first.

hope this will be last issue. Also, you need to add an if statement to check if there is at least on comment, then print it, otherwise you will get trying to get property of non object

Activity icon

Replied to Having Trouble With Relationship/collection ..

@bmartus ok

return $this->comments()->latest()->limit(1); // add () after comments
Activity icon

Replied to Having Trouble With Relationship/collection ..

Trying to get property of non object is this the error you get?

Jan
17
1 week ago
Activity icon

Replied to POST Route

@antoine_herbert Good, you are using CURL, here is the doc from php.net - https://www.php.net/manual/en/function.curl-setopt.php

// took from examples
$data = array('name' => 'Foo', 'file' => '@/home/user/test.png');

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
Activity icon

Replied to POST Route

@antoine_herbert that's totally different question..how do you send your request? using HTML Form? JavaScript? Postman? cURL? Any other mobile/desktop app?

Activity icon

Replied to Axios Ajax Call Not Working Working On Chrome But Working Safari

I can't even understand your post title

Jan
15
1 week ago
Activity icon

Replied to Deleting Duplicate Records

@inspiredprynce I don't know the structure of your tables, but what I can say is that you can GROUP by many columns, you mentioned per day, sign_in, roll_call and sign_out

GROUP BY DAY(create_at), sign_in, roll_call, sign_out

Hope I got it right

Activity icon

Replied to Deleting Duplicate Records

Hi,

// this query will return last ID of the grouped result of the given column
SELECT MAX(id) FROM your_table_name GROUP BY your_column_which_determinates_duplicates;

Let's take an example, tags table, id, name

id | name
----------------
1 | php
2 | laravel
3 | vue
4 | php
5 | ruby
6 | js
7 | vue
8 | js


SELECT MAX(id), name FROM tabs GROUP BY name; // this will return
id | name
----------------
2 | laravel
4 | php
5 | ruby
7 | vue
8 | js
// now if you have IDS which you don't want to delete, use `WHERE id NOT IN` 
DELETE FROM tags WHERE id NOT IN (
    SELECT * FROM (SELECT MAX(id) FROM tags GROUP BY name) AS ids
);
Jan
12
2 weeks ago
Activity icon

Replied to Approve/Deny Function In My Status Column.

if($borrowrequest->stauts = 1) {

shouldn't be == or === ?

the same is true for your elseif statement, you need comparison operator, not assignment

Jan
10
2 weeks ago
Activity icon

Awarded Best Reply on Get Latest Records From One Table And Insert Into Another Table

Hi

public function store(Request $request)
{
    request()->validate([
        'amount' => 'required',
        'comment' => 'required',
        'customer_id' => 'required'
    ]);

    $payment = Payment::create($request->all());

    DB::table('payment_credit_updates')->insert([
        'customer_id' => $payment->customer_id,
        'amount' => $payment->amount,
        'date' => $payment->created_at, 
        'type' => 'DR'
    ]);

    return redirect()->back() ->with('success','category created successfully.'); }
}
Activity icon

Replied to Get Latest Records From One Table And Insert Into Another Table

Hi

public function store(Request $request)
{
    request()->validate([
        'amount' => 'required',
        'comment' => 'required',
        'customer_id' => 'required'
    ]);

    $payment = Payment::create($request->all());

    DB::table('payment_credit_updates')->insert([
        'customer_id' => $payment->customer_id,
        'amount' => $payment->amount,
        'date' => $payment->created_at, 
        'type' => 'DR'
    ]);

    return redirect()->back() ->with('success','category created successfully.'); }
}
Activity icon

Replied to Nested Category Depth

@kalimeromk hope it helps :)

Schema::create('languages', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('name');
    $table->bigInteger('parent_id')->nullable();
});
Route::get('/', function () {
    // cache them if you don't change the often
    // you could even put them in local storage of the browser
    $languages = App\Language::with('children')->where('parent_id', 0)->get();

    return view('languages', compact('languages'));
});
@php
    function generateTree($languages, $level = 0)
    {
        foreach ($languages as $language) {
            if (count($language->children)) {
                echo '<option>', str_repeat("&mdash; ", $level) . $language->name, '</option>';
                generateTree($language->children, $level + 1);
            } else {
                echo '<option>', str_repeat("&mdash; ", $level) . $language->name . '</option>';
            }
        }
    }
@endphp

<select>
    @php generateTree($languages) @endphp
</select>

Activity icon

Replied to Property [company_avatar] Does Not Exist On This Collection Instance. (View: C:\xampp\htdocs\crm\resources\views\admin\login.blade.php)

@neeraj1005 would be nice to put this code in your controller, reason for this is that views should be dummy

// AdminLoginController.php

public function login()
{
    $data = Tbl_logo::find(1); // 1 should be dynamic I think
    // like Tbl_logo::where('company_id', auth()->id)->first();

    return view('admin.login', compact('data'));
}

this would be better

Activity icon

Awarded Best Reply on Property [company_avatar] Does Not Exist On This Collection Instance. (View: C:\xampp\htdocs\crm\resources\views\admin\login.blade.php)

$data = Tbl_logo::get(); // collection
$data = Tbl_logo::first() // model instance
$data = Tbl_logo::where('user_id', auth()->id)->first() // model instance
$data = auth()->user()->tbl->company_avatar // model instance if u have relationship

You need a model instance in order to access company_avatar

Activity icon

Replied to Property [company_avatar] Does Not Exist On This Collection Instance. (View: C:\xampp\htdocs\crm\resources\views\admin\login.blade.php)

$data = Tbl_logo::get(); // collection
$data = Tbl_logo::first() // model instance
$data = Tbl_logo::where('user_id', auth()->id)->first() // model instance
$data = auth()->user()->tbl->company_avatar // model instance if u have relationship

You need a model instance in order to access company_avatar

Jan
09
2 weeks ago
Activity icon

Replied to How To Login Then Go To Specific Link To Test ?

@mostafalaravel yes, but is bad practice to do test on your production database

public function test_links()
{
    $user = App\User::find($id); // $id is placeholder, App\User::find(1)

    $this->actingAs($user);
}
Activity icon

Replied to How To Login Then Go To Specific Link To Test ?

Hi, https://laravel.com/docs/5.1/testing#sessions-and-authentication

    public function testApplication()
    {
        $user = factory(App\User::class)->create();

        $this->actingAs($user)
Jan
08
2 weeks ago
Activity icon

Replied to What Do You Guys Use To Display A Loader Icon For A Component While Its HTTP Request Is Processing?

Assuming you are using Vue and Axios.

Axios Interceptors https://github.com/axios/axios#interceptors

Fire an event every time when request is send or response is received.

Catch the event with your <show-loader> component, and toggle it's visibility.

How to create EventBus file - https://alligator.io/vuejs/global-event-bus/

Interceptors

// bootstrap.js
window.axios.interceptors.request.use(function (config) {
    EventBus.$emit('toggle-loader', true);

    return config;
}, function (error) {
    EventBus.$emit('toggle-loader', false);

    return Promise.reject(error);
});

axios.interceptors.response.use(function (response) {
    EventBus.$emit('toggle-loader', false);

    return response;
}, function (error) {
    EventBus.$emit('toggle-loader', false);

    return Promise.reject(error);
});
// Loader.vue
<template>
    <img v-if="visible" src="/images/spinner.gif" alt="">
</template>

<script>
    import { EventBus } from "../event-bus";

    export default {
        name: "Loader",

        data: function () {
            return {
                visible: false
            }
        },

        created() {
            EventBus.$on('toggle-loader', (boolean) => {
                this.visible = boolean;
            });
        }
    }
</script>

Hope it works and it helps

Activity icon

Replied to Nginx Or Apache

You have to configure yourself.

Nginx or Apache - both work great. Some people like Nginx, others like Apache.

Activity icon

Awarded Best Reply on How To Make 'im' Unique

https://laravel.com/docs/5.8/validation#rule-unique

unique:table,column,except,idColumn
$this->validate($request, [
    'im' => ['required', 'string', 'max:6', 'unique:table,column']
]);
Jan
07
3 weeks ago
Activity icon

Replied to Laravel AutoComple Search

  1. Do you have errors in console?

  2. As you typing do you see any request sent to your server? ( network tab in browser's dev tools )

  3. Make sure you attach X-CSRF-TOKEN header to your request ( this is for Laravel )

<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
</script>
Activity icon

Replied to Error Of Undefined Property

@icelander Hi again, we had a conversation here - https://laracasts.com/discuss/channels/laravel/displaying-an-output

$result = [];

foreach($or as $items) {
    foreach($items as $serializedObject) {
        $result[] = unserialize($serializedObject);
    }
}

return view('profiles.orders', ['orders' => $result]);

let's try to add an if statement, and append to result array only if we have cart property, something like this:

$result = [];

foreach($or as $items) {
    foreach($items as $serializedObject) {
        $userializedObject = unserialize($serializedObject);

        if (property_exists ($userializedObject , 'cart') ) {
            $result[] = $userializedObject;
        }
    }
}

return view('profiles.orders', ['orders' => $result]);

I didn't test it, hope it helps

But, would be even better is you'd add some kind of validation before you save this serialized string into database.

Activity icon

Awarded Best Reply on Displaying An Output

@icelander

$orders = Auth::user()->transactions;
$or = $orders->map->only(['cart'])->all();

$result = [];

foreach($or as $serializedObject) {
    $result[] = unserialize($serializedObject[0]);
}

return view('profiles.orders', ['orders' => $result]);

something like this, not sure why you have nested array, if it may have more values, you need to add one more foreach

foreach($or as $items) {
    foreach($items as $serializedObject) {
        $result[] = unserialize($serializedObject);
    }
}
Activity icon

Replied to Displaying An Output

@icelander

$orders = Auth::user()->transactions;
$or = $orders->map->only(['cart'])->all();

$result = [];

foreach($or as $serializedObject) {
    $result[] = unserialize($serializedObject[0]);
}

return view('profiles.orders', ['orders' => $result]);

something like this, not sure why you have nested array, if it may have more values, you need to add one more foreach

foreach($or as $items) {
    foreach($items as $serializedObject) {
        $result[] = unserialize($serializedObject);
    }
}
Activity icon

Replied to Displaying An Output

Hi, looks like your object is serialized, probably you store this information as a string in your database, all you have to do is to unserialize the string - https://www.php.net/manual/en/function.unserialize.php

Activity icon

Replied to Artisan Serve

@mehmetanbaki sad :/

search in google, how to install LAMP and Composer, hope you will find a tutorial, and your OS will accept everything

Activity icon

Replied to Artisan Serve

@mehmetanbaki do you have composer.json in your root directory project? do you have vendor directory? do you know why a vendor directory and composer.json are needed?

Do you use GIT? or how you changed your OS?