mostafalaravel

mostafalaravel

Member Since 2 Years Ago

Experience Points
13,090
Total
Experience

1,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
1
Lessons
Completed
Best Reply Awards
0
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 3
13,090 XP
Oct
22
4 hours ago
Activity icon

Started a new Conversation Npm Run Watch : By IP Address

Hello ,

I use : npm run watch to run on local through http://localhost:3000/

Is there a way to make my app accessible by IP address then other users could find ?

Thanks

Oct
20
2 days ago
Activity icon

Replied to Eloquent Should I Use Where Or WhereHas

I think I found it :

But if there is something better please comment .

            $tasks = $tasks->where('task_status_id', '=', '2');
            $tasks = $tasks->where(function ($q) {
                $q->where('description', 'ilike', "%$this->querysearch%")
                    ->orWhereHas('teamleaderDeal', function ($query) {
                        $query->where('title', 'ilike', "%$this->querysearch%");
                    });
            });
Activity icon

Started a new Conversation Eloquent Should I Use Where Or WhereHas

hello

Here the code :

$tasks = $tasks
->where('description', 'ilike', "%$this->querysearch%"); --->condition_1 

$tasks = $tasks->where('task_status_id', '=', '2'); ---> condition_2

$tasks = $tasks->orWhereHas('teamleaderDeal', function ($query) {
                $query->where('title', 'ilike', "%$this->querysearch%");
            });  ---> condition_3

How to change this code to be :

(condition_1 OR condition_3) AND (condition_2)
Oct
17
5 days ago
Activity icon

Replied to How To Convert Array Form Depends To It's Content (objects)

@tykus

I need something like :

needArray= [
"1"=>"Domnic",
"2"=>"Bravo",
"3"=>"Sara",
"4"=>"Sara"
];
Activity icon

Replied to How To Convert Array Form Depends To It's Content (objects)

@tykus , Thanks,

maybe my question wasn't clear enough but is it possible that the array id got the same object id ?

because now : needArray[2] => "Sara" and it's supposed to returns "Bravo".

Activity icon

Started a new Conversation How To Convert Array Form Depends To It's Content (objects)

Hello ,

I would like to convert this array bellow :

let myArray = [
  {id: 4, name: "Sara"},
  {id: 3, name: "Sara"},
  {id: 1, name: "Domnic"},
  {id: 2, name: "Bravo"}
],

to have the array key same as id value:

needArray= [
"Domnic","Bravo","Sara","Sara"
];

to be able to get the name just by the needArray[2] => Bravo

Oct
16
6 days ago
Activity icon

Started a new Conversation Axios: How To Call Function Only When Data Is Ready?

Hello ,

I would like to know if there is a way to call getActivity() ONLY when getProfilesList() and getToolsList() are ready :

            getProfilesList() {
                axios.get(`/api/profiles`)
                    .then(response => {
                        this.profilesList = response.data;
                    });
            },

            getToolsList() {
                axios.get(`/api/tools`)
                    .then(response => {
                        this.toolsList = response.data;
                    });
            },

            getActivities(taskId) {
// do something.
}

Activity icon

Replied to How To Check If Sync Pivot Has Different Values ?

@tykus thanks, and how to use it in that code above ?

Activity icon

Started a new Conversation How To Check If Sync Pivot Has Different Values ?

Hello ,

how to check if the sync is dirty? I would like to create a log only if there is something changed .

     public function attachProfile(Task $task, array $profiles){
        try {
            $task->profiles()->sync($profiles);

            $causerId = Auth::user()->id;
            activity()
                ->performedOn($task)
                ->causedBy($causerId)
                ->withProperties([
                    $profiles
                ])
                ->log('update profile task');

        } catch (QueryException $e) {
            return $e;
        }
        return true;

    }
````
Oct
15
1 week ago
Activity icon

Replied to How To Convert Date Format Using Carbon

@yusuf128 thanks

what if I want this format : JAN 2019 JAN: January ?

Activity icon

Started a new Conversation How To Convert Date Format Using Carbon

Hello

I would like to convert this : 2019-10-15T10:14:58.000000Z to 15/10/2019 using carbon ?

Activity icon

Started a new Conversation Spatie/laravel-activitylog : Get All By Subject_type And Subject_id

Hello ,

I'm using this package : https://github.com/spatie/laravel-activitylog,

I would like to get all logs of specific subject Id and subject type

something like : where subject_id = 7 AND subject_type like 'App\Task'

thanks

Activity icon

Started a new Conversation What's The Best Timeline Package In VueJs

Hello ,

I'm looking to implement a timeline in my project , I found a lot of theme but i'm wondering which one is the best ?

thanks

Activity icon

Replied to Model Update: How To Check If There Is Changes ?

@tykus using traits :


     public function attachProfile(Task $task, array $profiles){
        try {
            $task->profiles()->sync($profiles);
        } catch (QueryException $e) {
            return $e;
        }
        return true;

    }

Activity icon

Replied to Model Update: How To Check If There Is Changes ?

@tykus yes exactly

        $task->save();

        if ($request->has('profiles') && ($request->profiles !== null)) {
            $addList = array_map(function ($ar) {
                return $ar['id'];
            }, $request->profiles);
            $this->attachProfile($task, $addList);
        }
Activity icon

Replied to Model Update: How To Check If There Is Changes ?

@tykus is it possible to use this when it's about many-to-many (pivot table) ?

Activity icon

Started a new Conversation Model Update: How To Check If There Is Changes ?

Hello

I would like to know if there is a way to check the data in model update before saving,

For example in my controller I want to save() only if there is some changes else I will return Nothing to save :

...
        $task->duration = $request->get('duration');
        $task->persons_number = $request->get('persons_number');
        $task->po_number = $request->get('poNumber');
        $task->repeat = $request->get('repeat');
        $task->teamleader_company_address_id = $request->get('companyAddressId');

        if ($request->has('departmentId')) {
            $task->department_id = $request->get('departmentId');
        }

        if ($request->has('statusId')) {
            $task->task_status_id = $request->get('statusId');
        }

        $task->save();

Thanks

Oct
11
1 week ago
Activity icon

Started a new Conversation How To Separate A Part Of Code In The Template To File

Hello ,

I would like to reuse the code bellow in other components , is it possible to put it in other file then to share it, to avoid the code duplication ?

<template>
...

        <div aria-hidden="true"
             aria-labelledby="editTaskModalLabel"
             class="modal fade"
             id="editTaskModal"
             role="dialog"
             tabindex="-1">
            <div role="document" v-bind:class="{'modal-lg':modalLarge, 'modal-dialog':true}">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="editTaskModalLabel">{{modalTitle}}</h5>
                        <button aria-label="Close" class="close" data-dismiss="modal" ref="closeEditModal"
                                type="button">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body" v-if="actionButton==='showEditTask'">
                        <edit-task ref="editTaskData"></edit-task>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-secondary btn-square" data-dismiss="modal" type="button">Close</button>
                        <button @click="editTask()" class="btn btn-primary btn-square" type="button"
                                v-if="actionButton==='showEditTask'"
                        ><i class="fa fa-floppy-o"></i> Save
                        </button>
                        <button class="btn btn-danger btn-square" data-dismiss="modal" type="button"
                                v-if="actionButton==='showDeleteTask'"><i class="fa fa-remove"></i> Delete
                        </button>
                    </div>
                </div>
            </div>
        </div>

...  
</template>     
Oct
08
2 weeks ago
Activity icon

Started a new Conversation How To Override This Css Class In Vue Js

Hello ,

I would like to make some modifications on the multiselect__tags

But it's not working !

<div class="multiselect__tags"><div class="multiselect__tags-wrap" style="display: none;"></div> <!----> <div class="multiselect__spinner" style="display: none;"></div> <input name="" id="inputProfile" type="text" autocomplete="nope" placeholder="Select profile(s)" tabindex="0" class="multiselect__input" style="width: 0px; position: absolute; padding: 0px;"> <!----> <span class="multiselect__placeholder">
          Select profile(s)
        </span></div>

Here what I did :

...
<style scoped>
    .multiselect__tags{min-height:40px;display:block;padding:8px 40px 0 8px;border-radius:5px;border:1px solid #f4b009;background: #ff0010;font-size:14px}
...

Isn't because of the CSS load ? I mean I should override this CSS after the origin is loaded not before ?

Activity icon

Started a new Conversation Vue-multiselect : How To Custom Css ?

Helllo ,

I would like to override the default CSS in vue-multiselect, https://vue-multiselect.js.org/

<multiselect :custom-label="customLabelProfilesList"
                                     :multiple="true"
                                     :options="profilesList"
                                     class="mmulti"
                                     id="inputProfile"
                                     placeholder="Select profile(s)" track-by="id"
                                     v-model="newTask.profiles"></multiselect>
<style scoped>
    .multiselect__tags {
        min-height: 32px;
        display: block;
        padding: 3px 40px 0 8px;
        border-radius: 5px;
        border: 1px solid #e8e8e8;
        background: #fff;
        font-size: 14px;
    }

But it's not working !

Activity icon

Replied to Does "npm Run Prod" Removes Console.log() ?

Thanks all :

this works with me :

mix.options({
    terser: {
        terserOptions: {
            compress: {
                drop_console: true,
            }
        }
    }
});
Activity icon

Replied to Does "npm Run Prod" Removes Console.log() ?

@ftiersch

I still capable to see the console.log()

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .browserSync('mostafa.icareweb.com');
mix.options

Then I : npm run prod

and hard refresh the browser

Activity icon

Started a new Conversation Does "npm Run Prod" Removes Console.log() ?

Hello

I'm wondering how to remove all console.log when I npm run prod ?

first is it possible ?

second if not is there any way to remove all console.log() in production ?

Thanks

Oct
07
2 weeks ago
Activity icon

Started a new Conversation Dynamic Input Value Related To Another Values

I would like to make the value ****here**** dynamic and related to the value of inputDuration (newTask.duration * 2 )

How to do it ?

                <div class="col-sm-2">
                    <div class="form-group">
                        <label for="inputDuration">Duration (H)</label>
                        <input class="form-control" id="inputDuration" min="4" step="4" type="number"
                               v-model="newTask.duration">
                    </div>
                </div>

                <div class="col-sm-2">
                    <div class="form-group">
                        <label for="inputWorkload">Workload</label>
                        <input disabled class="form-control" id="inputWorkload"  value="****here****"
                                >
                    </div>
                </div>

Activity icon

Started a new Conversation How To Pluralize Words In Vue Js

Hello ;

I would like to pluralize the result bellow : if memberAdded.length > 0 then members with S

<div class="col-sm">Add {{memberAdded.length}} members</div>

What's the best way ?

thanks

Oct
05
2 weeks ago
Activity icon

Started a new Conversation How To Multiple Destroy ?

hello ,

I user tinker to destroy some records one-by-one ,

>>> App\Permission::destroy(48);

How to destroy all id less than 70 for example ?

Thanks

Activity icon

Started a new Conversation Is It Possible To Search In Json Data?

Hello ,

I'm wondering if there is a way in Laravel to store json string in a column and make a search in side that json data , something like what we do with Eloquent.

any tutorial link is welcome.

thanks

Oct
04
2 weeks ago
Activity icon

Started a new Conversation How To Custom Resources Controller With Specific Middleware

I have this controller bellow ,

How to add a middleware to only update and destroy and store methods ?

    Route::resource('api/tasks', 'TaskController', [
        'only' => ['index', 'show', 'store', 'update', 'destroy']
    ])->middleware(['tasks_view']);

Thanks

Activity icon

Replied to How To Use Middleware In Blade ?

Update : I added one condition , and it seems working !

    <div class="py-1">
        <div class="row justify-content-center">
            <div class="col-md-12">
                <tasks
                :auth-user="{{ (Gate::allows('tasks_eddit'))?'1':'0' }}"
                ></tasks>
            </div>
        </div>
    </div>
Activity icon

Replied to How To Use Middleware In Blade ?

@nakov

Thanks again ,

This bellow works for me but when the {{ Gate::allows('tasks_edit') }} returns false I have this error

[Vue warn]: Error compiling template:

The value for a v-bind expression cannot be empty. Found in "v-bind:auth-user"

    <div class="py-1">
        <div class="row justify-content-center">
            <div class="col-md-12">
                <tasks
                :auth-user="{{ Gate::allows('tasks_edit') }}"
                ></tasks>
            </div>
        </div>
    </div>

How to do when It's false return false instead of empty ?

Activity icon

Replied to How To Use Middleware In Blade ?

@nakov Thanks it works ,

Another question , how I could use this in VueJS for example :

                            <button :disabled="findInMembers(row.id)"
                                    class="btn btn-square btn-success align-center"
                                    slot="actions" slot-scope="{row}"
                                    type="button"
                                    v-on:click="addMembersToList(row)">
                Add
                            </button>

let's say that this button is only shown if @can('companies_view')

Activity icon

Started a new Conversation How To Use Middleware In Blade ?

Hello ,

I would like to use some middlewares in the blade view ,

These middlewares are used already in the route :

    Route::view('/companies', 'irp.companies.companies')->middleware(['verified','companies_view'])->name('Companies');
    Route::view('/deals', 'irp.deals.deals')->middleware(['verified','projects_view'])->name('Deals');
    Route::view('/tasks', 'irp.tasks.tasks')->middleware(['verified','tasks_view'])->name('Tasks');

now in sidebar.blade.php I would like to show the related links to the above routes only when user has the permission (conditions):

                    <a class="nav-link " href="/companies">
                        <i class="nav-icon fa fa-industry"></i> Companies
                    </a>


                    <a class="nav-link " href="/deals">
                        <i class="fa fa-cubes" aria-hidden="true"></i> Projects
                    </a>


                    <a class="nav-link " href="/tasks">
                        <i class=" nav-icon fa fa-tasks" aria-hidden="true"></i> Tasks
                    </a>

Activity icon

Started a new Conversation Middleware Name

hello ,

I'm wondering if there is no problem to name the middleware : group_view instead of GroupView?

php artisan make:middleware groups_view

Oct
03
2 weeks ago
Activity icon

Started a new Conversation How To Return Only Related Models In Relationship With Specific User ?

Hello ,

the code bellow :

    return \App\Group::with(['users' => function($query) {
        $query->select('name');
    }, 'permissions' => function($query) {
        $query->select('name');
    }])->get();

returns the Groups with permissions and users:

{
    "id": 15,
    "name": "Russell Terrace",
    "slug": "russell-terrace",
    "created_at": "2019-07-26 11:13:34",
    "updated_at": "2019-07-26 11:13:34",
    "deleted_at": null,
    "users": [
      {
        "email": "[email protected]",
        "pivot": {
          "group_id": 15,
          "user_id": 11
        }
      },
      {
        "email": "[email protected]",
        "pivot": {
          "group_id": 15,
          "user_id": 17
        }
      },
...

How to get only the Groups of a specific user (user id= 211) ?

thanks

Activity icon

Replied to How To Get Only Ids From The Related Model ?

@geowrge this returns the user Id (221) but i'm looking for the groups Ids

Activity icon

Started a new Conversation How To Find In Relation Ship ?

I have a many to many relation ship between Groups and Users :

Users model :

    public function groups()
    {
        return $this->belongsToMany(Group::class);
    }

Groups models :

    public function users()
    {
        return $this->belongsToMany(User::class);
    }

How to get all groups having the user id=5 (for example) ?

I have now :

return \App\Group::all();
Activity icon

Started a new Conversation How To Get Only Ids From The Related Model ?

Hello ,

Here the code :

    return \App\User::where('id', 221)->with('groups')->get();

as you can see bellow it returns the groups with all attributes but I would like to have only the "Ids" of these groups !

[
  {
    "id": 221,
    "name": "Trisha Feil",
    "email": "[email protected]",
    "email_verified_at": "2019-07-26 11:13:34",
    "verified": "1",
    "verified_token": null,
    "admin": "false",
    "created_at": "2019-07-26 11:13:35",
    "updated_at": "2019-07-26 11:13:35",
    "first_name": "Raegan",
    "last_name": "Adams",
    "telephone": "902.715.9743 x27445",
    "job_title": "Editor",
    "abbreviation": "qnf",
    "start_date": "2009-03-05",
    "stop_date": "1963-05-01",
    "birth_date": null,
    "street": "96501 Corbin Forks Apt. 055",
    "city": "Altenwerthview",
    "post_code": "25665-6203",
    "country": "CH",
    "deleted_at": null,
    "password_update_count": 3,
    "password_last_update_date": "2019-07-31",
    "logout": false,
    "password_updated_by": null,
    "teamleader": null,
    "planner": null,
    "language": null,
    "is_internal": false,
    "report_department": null,
    "avatar": "user.jpg",
    "groups": [
      {
        "id": 21,
        "name": "Schroeder Station",
        "slug": "schroeder-station",
        "created_at": "2019-07-26 11:13:34",
        "updated_at": "2019-07-26 11:13:34",
        "deleted_at": null,
        "pivot": {
          "user_id": 221,
          "group_id": 21
        }
      },
      {
        "id": 23,
        "name": "Kathryne Run",
        "slug": "kathryne-run",
        "created_at": "2019-07-26 11:13:34",
        "updated_at": "2019-07-26 11:13:34",
        "deleted_at": null,
        "pivot": {
          "user_id": 221,
          "group_id": 23
        }
      },
      {
        "id": 73,
        "name": "Edit tasks",
        "slug": "edit-tasks",
        "created_at": "2019-10-03 14:46:38",
        "updated_at": "2019-10-03 14:46:38",
        "deleted_at": null,
        "pivot": {
          "user_id": 221,
          "group_id": 73
        }
      }
    ]
  }
]
Activity icon

Started a new Conversation Middleware: How To Use 'OR' Statement In Router

Hey ,

I have two middlewres : admin and create_task,

in the router :

 Route::view('/tasks', 'irp.tasks.tasks')->middleware(['verified'])->name('Tasks');

How to make this route accessible if user has admin OR create_task middleware

Thanks

Oct
02
2 weeks ago
Activity icon

Started a new Conversation How To Import A JS File In Vue ?

Hello ,

I created a function in a file getAllUrlParams.js :

function getAllUrlParams(url) {

    // get query string from url (optional) or window
    var queryString = url ? url.split('?')[1] : window.location.search.slice(1);

    // we'll store the parameters here
    var obj = {};

    // if query string exists
    if (queryString) {
...

I woulf like to use that function in my vue file :

<script>
    import taskDetails from "./taskDetails";
    import companyDetails from "../companies/companyDetails";
    import addTask from "./addTask";
    import editTask from "./editTask";

    export default {
        name: "tasks",
        components: {

1- how to import it ?

2- what is the best place to put that JS file ?

Thanks

Oct
01
3 weeks ago
Activity icon

Replied to How To Get Url Params ?

@nakov

Here the message I got :`

app.js:127994 [Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'query' of undefined"

found in

---> <Tasks> at resources/js/components/irp/tasks/tasks.vue
       <Root>

about your question : Have you installed vue router btw? No not yet , is it mandatory to get url params ?

Activity icon

Started a new Conversation How To Get Url Params ?

Hello I would like to get the URL params but it's not working ! :

        mounted() {
            console.log(this.$route.query.test)
...
        },

http://localhost:3000/tasks?test=hello

Activity icon

Replied to How To Show Only 3 First Words Of A Text Variable ?

thanks @mikemacdowell

I made this filter bellow :

Vue.filter('sentenceCutter', function(value,nbrWords) {
    if (value) {
         return  value.replace(/(([^\s]+\s\s*){2})(.*)/,"…");
    }
});

then :

<h5 class="modal-title" id="deleteTaskModalLabel">{{modalTitle |sentenceCutter(3)}}</h5>

But now the filter is static on two words : ...s\s*){2})(.*)/,"$...

How to use the parameter ?

Activity icon

Replied to Soft Delete Not Working : Delete Completely The Row

@b3ndoi I forgot it but now it works

Activity icon

Started a new Conversation How To Show Only 3 First Words Of A Text Variable ?

Hello

I would like to show only the 3 first words of the variable and prefix it with dots only if it's larger (...)

Now I did this bellow but I want to change it :

<h5 class="modal-title" id="deleteTaskModalLabel">{{modalTitle.substring(0,8) + " ..." }}</h5>
Activity icon

Replied to Soft Delete Not Working : Delete Completely The Row

I found it :

I forgot to add this bellow to the model :

    use SoftDeletes;

Thanks