mostafalaravel

mostafalaravel

Member Since 3 Years Ago

Experience Points
21,100
Total
Experience

3,900 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 your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 5
21,100 XP
Mar
26
3 days ago
Activity icon

Replied to Page 404 After New Installation !

@sergiu17 yes I have it !

|        | POST      | login                                            |                                    | App\Http\Controllers\Auth\[email protected]                              | web,guest                        |
|        | GET|HEAD  | login                                            | login                              | App\Http\Controllers\Auth\[email protected]                      | web,guest                        |
|

the 404 error is not from laravel it's from the server because I customized my 404 error !

Activity icon

Replied to Page 404 After New Installation !

@sergiu17 it couldn't be a problem of redirection ? (server side)

because:

First let me show you the router part :

Route::get('/', function () {
    if (Auth::check()) return redirect('/myprofile');
    return redirect('/login');
});

when I change this route:

Route::get('/', function () {
    return 'hello world'
});

it works and I can see hello world

also the 404 error is from the server not from laravel !

Activity icon

Replied to Page 404 After New Installation !

@sergiu17 I have this error :

 sudo composer require laravel/ui
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Using version ^2.0 for laravel/ui
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove laravel/framework v5.8.36
    - Conclusion: don't install laravel/framework v5.8.36
    - laravel/ui 2.x-dev requires illuminate/console ^7.0 -> satisfiable by illuminate/console[7.x-dev, v7.0.0, v7.0.1, v7.0.2, v7.0.3, v7.0.4, v7.0.5, v7.0.6, v7.0.7, v7.0.8, v7.1.0, v7.1.1, v7.1.2, v7.1.3, v7.2.0, v7.2.1, v7.2.2, v7.3.0], laravel/framework[7.x-dev].
    - laravel/ui v2.0.0 requires illuminate/console ^7.0 -> satisfiable by illuminate/console[7.x-dev, v7.0.0, v7.0.1, v7.0.2, v7.0.3, v7.0.4, v7.0.5, v7.0.6, v7.0.7, v7.0.8, v7.1.0, v7.1.1, v7.1.2, v7.1.3, v7.2.0, v7.2.1, v7.2.2, v7.3.0], laravel/framework[7.x-dev].
    - laravel/ui v2.0.1 requires illuminate/console ^7.0 -> satisfiable by illuminate/console[7.x-dev, v7.0.0, v7.0.1, v7.0.2, v7.0.3, v7.0.4, v7.0.5, v7.0.6, v7.0.7, v7.0.8, v7.1.0, v7.1.1, v7.1.2, v7.1.3, v7.2.0, v7.2.1, v7.2.2, v7.3.0], laravel/framework[7.x-dev].
    - Can only install one of: laravel/framework[7.x-dev, v5.8.36].
    - don't install illuminate/console 7.x-dev|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.0|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.1|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.2|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.3|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.4|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.5|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.6|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.7|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.0.8|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.1.0|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.1.1|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.1.2|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.1.3|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.2.0|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.2.1|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.2.2|don't install laravel/framework v5.8.36
    - don't install illuminate/console v7.3.0|don't install laravel/framework v5.8.36
    - Installation request for laravel/framework (locked at v5.8.36, required as 5.8.*) -> satisfiable by laravel/framework[v5.8.36].
    - Installation request for laravel/ui ^2.0 -> satisfiable by laravel/ui[2.x-dev, v2.0.0, v2.0.1].


Installation failed, reverting ./composer.json to its original content.

Activity icon

Replied to Page 404 After New Installation !

@sergiu17 No! should I install it ?

Activity icon

Started a new Conversation Page 404 After New Installation !

Hello ,

after cloning Laravel I have this issue :

when I use my access my domain https://just-for-example.com i'm redirected to https://just-for-example.com/login which is normal, but instead to see the login page I have 404 error page !

please help

Activity icon

Started a new Conversation Composer Update: SQLSTATE[42501]: Insufficient Privilege: 7 ERROR: Permission Denied For Table Teamleader_apis (SQL: Select * From "teamleader_apis" Limit 1)

Hello ,

I cloned my project and then I created the .env with all new parameters (database password , username ...)

now when I : composer install I have this error message !

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

  Illuminate\Database\QueryException  : SQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied for table teamleader_apis (SQL: select * from "teamleader_apis" limit 1)

 at /data/www/irpacc.icareweb.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
   660|         // If an exception occurs when attempting to run a query, we'll format the error
   661|         // message to include the bindings with SQL, which will make this exception a
   662|         // lot more helpful to the developer instead of just the database's errors.
   663|         catch (Exception $e) {
 > 664|             throw new QueryException(
   665|                 $query, $this->prepareBindings($bindings), $e
   666|             );
   667|         }
   668|

 Exception trace:

 1   App\Console\Commands\DemoCron::__construct()
     [internal]:0

 2   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied for table teamleader_apis")
     /data/www/irpacc.icareweb.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:123

 Please use the argument -v to see more details.

Mar
24
5 days ago
Activity icon

Started a new Conversation How To "concate" In Eloquent

Hello ,

In user table I have first_name and last_name, I would like to get users where : full name equal to will smith

something like : WHERE CONCAT(first_name, ' ', last_name) = "will smith"

Thanks

Mar
23
6 days ago
Activity icon

Started a new Conversation How To Add Condition "where Not Equal" In Validation ?

I want to add one condition to 'segments.*.builder' => 'required', where segments.*.builder should not equal to "abc" ?

        $request->validate([
            'name' => 'required',
            'segments.*.builder' => 'required',
            'segments.*.value' => 'required',
        ]);

Thanks

Mar
16
1 week ago
Activity icon

Started a new Conversation How To Add Condition To Validation ?

Hello ,

I have the validation bellow :

        $request->validate([
            'name' => 'required',
            'segments.*.builder' => 'required',
            'segments.*.value' => 'required',
        ]);
````
I'm wondering how to add another condition :  If the value of `segments.*.builder` exists  in [13,15] , do not ` 'segments.*.value' => 'required',` 

if the `segments.*.builder` is 15 or 13 do not require  ` 'segments.*.value' => 'required',`

thanks
Activity icon

Started a new Conversation How To Create Global Constant In Laravel Which I Can Use In VueJS ?

Hello ,

In my component I have :

data() {
			return {
				buildersWithoutValues:[13,15],
(...)

I would like to instead of hard coding : buildersWithoutValues, I want to store [13,15] in a constant then use it .

Note : I use this component from a Blade file ,

    <div class="py-1">
        <div class="row justify-content-center">
            <div class="col-md-12">
                <competences
                        :authrz-public-segment-edit="{{ (Gate::allows('public_segment_edit')) ?  : 0 }}"
                        :login-user-id = "{{ Auth::user()->id }}"
                        :authrz-competences-edit="{{ (Gate::allows('competences_edit')) ?  : 0 }}"

                ></competences>
            </div>
        </div>
    </div>
Mar
13
2 weeks ago
Activity icon

Replied to How To Rename The Object Key Name ?

@sinnbeck it's an array of object , not a model just a simple variable

Activity icon

Started a new Conversation How To Rename The Object Key Name ?

Hello,

I would like to change user_id to id of the array of object bellow :

{
      "user_id": 1,
      "user_full_name": "abc vij"
    },
    {
      "user_id": 504,
      "user_full_name": "Bruno hello"
    },
    {
      "user_id": 510,
      "user_full_name": "hey how are "
    },
    {
      "user_id": 503,
      "user_full_name": "sd abc"
    },
    {
      "user_id": 514,
      "user_full_name": "sd hello"
    }

What's the best way ?

Mar
11
2 weeks ago
Activity icon

Started a new Conversation How Call A Function When .then() Is Done ?

Hello ,

I would like to call getMember() only when axios.get().then() is done :

            return {
		(...)
                members: [],
		(...)
            getMembers() {
                axios.get(`/api/members`)
                    .then(response => {
                        this.members = response.data;
                    });
            },
            getCertificateById(id) {
                console.log("certificat by id", id);
                axios.get(`/api/certificates/`+id)
                    .then(response => {
                        this.newCertificate.certificateBody = response.data.certificate_body;
                        this.newCertificate.certificateNumber = response.data.certificate_number;
                        this.newCertificate.link = response.data.link;
                        this.newCertificate.comment = response.data.comment;
                        this.newCertificate.expirationDate = Date.parse(response.data.expiration_date);

                        this.getMembers(); 
			// (1)  I call this method to fill the members table 

                        this.newCertificate.member = this.members.find( ({ id }) => id ==  response.data.user_id);
			// (2) I want to filter 'this.members' only when it's not empty(after filling)
		
                    });
            },

please read comments (1) and (1)

I need something like : this.getMembers().then(//do something)

Mar
09
2 weeks ago
Activity icon

Replied to Carbon : How To Get Only Date Without Time ?

@snapey the value now is like : 2020-03-03 (string type and also the table column type is string -required to be string-) Carbon::parse($seg["value"])->format('Y-m-d');

Activity icon

Replied to Carbon : How To Get Only Date Without Time ?

Thanks @sinnbeck @snapey

the @sinnbeck answer is working :Carbon\Carbon::now()->toDateString(); I restarted the server and it works (no idea what was the problem)

Activity icon

Replied to Carbon : How To Get Only Date Without Time ?

@sinnbeck yes that's true but when I check the DB table I see : 2020-03-13T11:20:00.000Z I need just 2020-03-13

Activity icon

Replied to Carbon : How To Get Only Date Without Time ?

@sinnbeck thanks, but same problem :

the $condition->value type is string not date (It must be string , I cant change it )

Activity icon

Started a new Conversation Carbon : How To Get Only Date Without Time ?

Hello ,

I try to get only the date without time :

$condition->value=Carbon::parse($seg["value"])->format('d-m-Y');

but the result is : 2020-03-17T11:07:00.000Z

How to keep only the Date ? 2020-03-17

Activity icon

Awarded Best Reply on Eloquent: How To Filter Results By Relationship

@bugsysha thanks ,

I think I found it :

TeamleaderCompany::whereHas('teamleaderCompanyTags', function ($query) {
        $query->where('tag', 'reseller');
    })
    ->whereDoesntHave('teamleaderCompanyTags', function ($query) {
        $query->where('tag', '!=', 'reseller');
    })
    ->get()
Mar
06
3 weeks ago
Activity icon

Replied to Eloquent: How To Filter Results By Relationship

@bugsysha thanks ,

I think I found it :

TeamleaderCompany::whereHas('teamleaderCompanyTags', function ($query) {
        $query->where('tag', 'reseller');
    })
    ->whereDoesntHave('teamleaderCompanyTags', function ($query) {
        $query->where('tag', '!=', 'reseller');
    })
    ->get()
Activity icon

Started a new Conversation Eloquent: How To Filter Results By Relationship

Hello ,

I have two models TeamleaderCompany which : has many TeamleaderCompanyTag

TeamleaderCompany

    public function teamleaderCompanyTags()
    {
        return $this->hasMany('App\TeamleaderCompanyTag');
    }

TeamleaderCompanyTag

    public function teamleaderCompany()
    {
        return $this->belongsTo(TeamleaderCompany::class);
    }
}

when I TeamleaderCompany::all() I have this results :

(...)
      "teamleader_company_tags": [
        {
          "id": 7,
          "tag": "hot lead",
          "teamleader_company_id": 3,
          "created_at": "2019-09-03 09:23:51",
          "updated_at": "2019-09-03 09:23:51"
        },
        {
          "id": 8,
          "tag": "reseller",
          "teamleader_company_id": 3,
          "created_at": "2019-09-03 09:23:51",
          "updated_at": "2019-09-03 09:23:51"
        }
      ]
(...)

What I'm trying to do is to : show TeamleaderCompany results where teamleader_company_tags has only Tags =='reseller' (if there is another tag except 'reseller' don't show)

 $companies->whereHas(
	'teamleaderCompanyTags',
	function ($query) use ($condition) {
	$query->where('tag',
(...)
 );
 }
);

thanks

Mar
04
3 weeks ago
Activity icon

Started a new Conversation Is It Possible To Convert Accessor To Eloquent Condition ?

I have this Accessor bellow which returns one string result (example: 'Ready' or 'Ongoing' ...):

    public function getMinimumStatusAttribute()
    {
        $statusIds = [];
        $tasks = $this->tasks()->get();
        foreach ($tasks as $task) {
            array_push($statusIds, $task->task_status_id);
        }

        return taskStatus::orderBy('order', 'asc')
            ->where('operational_status', '=', true)
            ->whereIn('id', $statusIds)->value('name');
    }

I have TeamleaderDeal model :

return TeamleaderDeal::all();

which returns:


[
  {
    "id": 4,
    "teamleader_id": "8b03da5a-af1f-051d-ad6d-b6199c7f7c35",
    "created_at": "2019-09-09 11:41:46",
    "updated_at": "2019-09-14 20:57:03",
    "title": "Brand identity #2",
    "reference": "12",
    "lead_company_id": "adeddc13-6962-0a19-ac72-6713d1cf1455",
    "teamleader_company_id": 1,
    "dealphase_id": "199a34fc-de5c-038d-a655-c61fa4d97d17",
    "estimated_closing_date": null,
    "po_number": "az215487",
    "teamleader_deal_phase_id": 6,
    "dealPhase": "Refused",
    "tasksCount": 5,
    "companyLanguage": "nl",
    -------------------------
    "minimumStatus": "ready", ||||||accessor results
    -------------------------
    "invoiced": 1,
(...)

I would like to filter TeamleaderDeal results by MinimumStatus to show for example only results where MinimumStatus equal to 'Ready' ?

Thanks

Mar
03
3 weeks ago
Activity icon

Replied to How To Convert Object Result To Array Of Objects

I think I found it :

Is there something more clean than this solution ?

        $filtered = $exportTemplates->filter(function($d){
            return collect($d->ExportTemplateColumns)->filter(function($columns){
                return $columns->SearchableColumn->searchable_table_id ==  $this->segmentTableId;
            })->count();
        });

        $templates = [];
        foreach ($filtered as $key=>$val){
            $templates[] = $val->toArray();
        }

        return $templates;
Activity icon

Started a new Conversation How To Convert Object Result To Array Of Objects

Hello

This is my code :

$exportTemplates = ExportTemplate::where('user_id', Auth::id())->get();

        $filtered = $exportTemplates->filter(function($d){
            return collect($d->ExportTemplateColumns)->filter(function($columns){
                return $columns->SearchableColumn->searchable_table_id ==  $this->segmentTableId;
            })->count();
        });

return $filtered->all();

I want to return an array of objects instead of this:

{
  "0": {<-----------------------
    "id": 45,
    "name": "hallo",
    "user_id": 1,
    "deleted_at": null,
    "created_at": "2020-02-27 14:12:50",
    "updated_at": "2020-02-27 14:12:50",
    "ExportTemplateColumns": [
      {
        "id": 398,
        "export_template_id": 45,
        "searchable_column_id": 7,
        "created_at": "2020-02-27 14:12:50",
        "updated_at": "2020-02-27 14:12:50",
        "SearchableColumn": {
          "id": 7,
          "name": "bic",
          "type": "string",
          "searchable_table_id": 1,
          "created_at": "2020-02-06 09:11:24",
          "updated_at": "2020-02-06 09:11:30",
          "label": "BIC"
        }
      }
    ]
  },
  "3": {<----------------------------
    "id": 39,
    "name": "abc",
    "user_id": 1,
    "deleted_at": null,
    "created_at": "2020-02-26 15:49:57",
    "updated_at": "2020-02-27 10:38:34",
    "ExportTemplateColumns": [
      {
        "id": 396,
        "export_template_id": 39,
        "searchable_column_id": 9,
        "created_at": "2020-02-27 14:12:41",
        "updated_at": "2020-02-27 14:12:41",
        "SearchableColumn": {
          "id": 9,
          "name": "preferred_currency",
          "type": "string",
          "searchable_table_id": 1,
          "created_at": "2020-02-06 09:11:26",
          "updated_at": "2020-02-06 09:11:28",
          "label": "Currency"
        }
      },
      {
        "id": 397,
        "export_template_id": 39,
        "searchable_column_id": 2,
        "created_at": "2020-02-27 14:12:41",
        "updated_at": "2020-02-27 14:12:41",
        "SearchableColumn": {
          "id": 2,
          "name": "email",
          "type": "string",
          "searchable_table_id": 1,
          "created_at": "2020-02-06 09:06:25",
          "updated_at": "2020-02-06 09:06:34",
          "label": "Email"
        }
      }
    ]
  },(...)

I want to convert it to an Array of objects, like :

[
 {
    "id": 45,
    "name": "hallo",
    "user_id": 1,
    "deleted_at": null,
    "created_at": "2020-02-27 14:12:50",
    "updated_at": "2020-02-27 14:12:50",
    "ExportTemplateColumns": [
      {
        "id": 398,
        "export_template_id": 45,
        "searchable_column_id": 7,
        "created_at": "2020-02-27 14:12:50",
        "updated_at": "2020-02-27 14:12:50",
        "SearchableColumn": {
          "id": 7,
          "name": "bic",
          "type": "string",
          "searchable_table_id": 1,
          "created_at": "2020-02-06 09:11:24",
          "updated_at": "2020-02-06 09:11:30",
          "label": "BIC"
        }
      }
    ]
  },
{
    "id": 39,
    "name": "abc",
    "user_id": 1,
    "deleted_at": null,
    "created_at": "2020-02-26 15:49:57",
    "updated_at": "2020-02-27 10:38:34",
    "ExportTemplateColumns": [
      {
        "id": 396,
        "export_template_id": 39,
        "searchable_column_id": 9,
        "created_at": "2020-02-27 14:12:41",
        "updated_at": "2020-02-27 14:12:41",
        "SearchableColumn": {
          "id": 9,
          "name": "preferred_currency",
          "type": "string",
          "searchable_table_id": 1,
          "created_at": "2020-02-06 09:11:26",
          "updated_at": "2020-02-06 09:11:28",
          "label": "Currency"
        }
      },
      {
        "id": 397,
        "export_template_id": 39,
        "searchable_column_id": 2,
        "created_at": "2020-02-27 14:12:41",
        "updated_at": "2020-02-27 14:12:41",
        "SearchableColumn": {
          "id": 2,
          "name": "email",
          "type": "string",
          "searchable_table_id": 1,
          "created_at": "2020-02-06 09:06:25",
          "updated_at": "2020-02-06 09:06:34",
          "label": "Email"
        }
      }
    ]
  },(...)

thanks

Mar
02
3 weeks ago
Activity icon

Started a new Conversation Eloquent : How To Make A Condition To Relation Ship Attributes ?

Hello ,

In the controller :

    public function index(Request $request)
    {

        $exportTemplate = ExportTemplate::where('user_id', Auth::id())->get();
        return $exportTemplate;
    }

The result is :

[
  {
    "id": 45,
    "name": "hallo",
    "user_id": 1,
    "deleted_at": null,
    "created_at": "2020-02-27 14:12:50",
    "updated_at": "2020-02-27 14:12:50",
    "ExportTemplateColumns": [
      {
        "id": 398,
        "export_template_id": 45,
        "searchable_column_id": 7,
        "created_at": "2020-02-27 14:12:50",
        "updated_at": "2020-02-27 14:12:50",
        "SearchableColumn": {
          "id": 7,
          "name": "bic",
          "type": "string",
          "searchable_table_id": 1,
          "created_at": "2020-02-06 09:11:24",
          "updated_at": "2020-02-06 09:11:30",
          "label": "BIC"
        }
      }
    ]
  },
  {
    "id": 46,
    "name": "fol",
    "user_id": 1,
(...)

question: how to return only results where :

ExportTemplateColumns->SearchableColumn->searchable_table_id = 1

Models :

class ExportTemplate extends Model
{


    protected $appends = ["ExportTemplateColumns"];


    public function getExportTemplateColumnsAttribute()
    {
        return ExportTemplatesColumns::where('export_template_id',$this->id)->get();
    }

    public function user()
    {
        return $this->belongsTo(User::class,'id');
    }

    public function exportTemplatesColumns()
    {
        return $this->hasMany(ExportTemplatesColumns::class,'export_template_id');
    }

}
class ExportTemplatesColumns extends Model
{

    protected $appends = ["SearchableColumn"];


    public function getSearchableColumnAttribute()
    {
        return SearchableColumn::find($this->searchable_column_id);
    }


    public function exportTemplate()
    {
        return $this->belongsTo(ExportTemplate::class,'id');
    }

    public function searchableColumn()
    {
        return $this->belongsTo(SearchableColumn::class,'id');
    }



}

Activity icon

Replied to Eloquent: How To Where Count Relation Ship ?

@snapey

I have two models : TeamleaderDeal and Task .

the relationship is :

TeamleaderDeal model:

    public function tasks()
    {
        return $this->hasMany('App\Task');
    }


    public function getTasksCountAttribute()
    {
        return $this->hasMany('App\Task')->count();
    }

Task model:

    public function teamleaderDeal()
    {
        return $this->belongsTo(TeamleaderDeal::class);
    }

I want to make a condition to show only teamleaderDeals having more than X number of tasks :

        $deals = TeamleaderDeal::orderBy($this->sorting, $this->sortOrder);

return (

//
//I want to return only deals with X number of tasks !
//

)
Activity icon

Replied to Eloquent: How To Where Count Relation Ship ?

@amaury Thanks , `

It says that column doesn't exists :

SQLSTATE[42703]: Undefined column: 7 ERROR: column "tasks_count" does not exist LINE 1
Activity icon

Started a new Conversation RelationShip Count : Undefined Column "task_count" Does Not Exist

Hello ,

I try to filter the TeamleaderDeal results by number of tasks (equal to 5):

$deals = TeamleaderDeal::withCount('tasks as task_count');
(...)
return $deal->where('tasks_count',5)->paginate($limit);

model : TeamleaderDeal

    public function tasks()
    {
        return $this->hasMany('App\Task');
    }

But I got this error message :

SQLSTATE[42703]: Undefined column: 7 ERROR: column "task_count" does not exist LINE 1: ...unt(*) as aggregate from "teamleader_deals" where "task_count... ^ (SQL: select count(*) as aggregate from "teamleader_deals" where "task_count" = 5)

Thanks

Mar
01
4 weeks ago
Activity icon

Started a new Conversation Eloquent: How To Where Count Relation Ship ?

In my model TeamleaderDeal :

    public function tasks()
    {
        return $this->hasMany('App\Task');
    }

controller:

(...)
 $deals = TeamleaderDeal::orderBy($this->sorting, $this->sortOrder);
(...) 
$deals->whereHas(
                                'tasks',
                                function ($query) use ($condition) {
                                    dd($query);
                                }

How to make this condition? : where count of the relation ship tasks equal to 5

thanks

Feb
28
1 month ago
Activity icon

Replied to Is It Possible To Create A Directory In Traits Directory ?

@sti3bas Thanks it works !

one more question : is it possible to call a trait from another trait ?

because I have one method which is repeated in multiple traits and I would like to put is in a separated trait to avoid code repetition !

Activity icon

Started a new Conversation Is It Possible To Create A Directory In Traits Directory ?

Hello ,

I would like to create a directory Abc inside the Traits directory where I will put some Traits files

but it's not working !

Traits
---------|
             Abc
             ------|Trait1.php
                    | Traits2.php
                    | Traits2.php
                    | Traits2.php

Activity icon

Replied to How To Call Methods From External File In Vue Js ?

@amaury one more question : is it possible to use mixins also to share template ?

Feb
27
1 month ago
Activity icon

Started a new Conversation How To Call Methods From External File In Vue Js ?

Hello ,

First, this is my component content :

<template lang="html">
  <div id="sec">
    <p>Hello</p>
  </div>
</template>

<script>
import { ipcRenderer } from 'electron'
export default {
    data () {
      return {
        // data
      }
    },
    methods: {
      doWork () {
        // the work
      },

      firstMethod() {
        // the work
      }
    }
  
}

I want to move the method doWork() to an external js file other-methods.js to keep my code clean .

Is it possible ? if yes , How?

Feb
25
1 month ago
Activity icon

Started a new Conversation How To Make This Condition With Eloquent ?

Hello:

I would like to add OR statement inside the bellow condition :

        $segment = Segment::orderBy('name')
            ->where('table_name', '=', $tableName)
            ->where('user_id', auth()->id()) <======= this line
            ->with('conditions');
        return $segment->get();

the condition: ->where('user_id', auth()->id()) I need to change it to something like :

 ->where('user_id' == auth()->id() OR 'public'== true)

the OR should be just inside : ->where('user_id', auth()->id())

Activity icon

Replied to How To Seed The Prod Database ?

Thank you all !

Feb
24
1 month ago
Activity icon

Started a new Conversation How To Seed The Prod Database ?

Hello ,

In some cases I need to seed some tables : like countries because it has known data,

Actually I do it via a dump export , is this way good? or there is some other ways much better ?

Thanks

Activity icon

Replied to Laravel Excel : How To Export Only Some Columns ?

@sti3bas

unfortunately I need multiple columns !

Activity icon

Replied to Laravel Excel : How To Export Only Some Columns ?

Note :

When I return TeamleaderCompany::get(); I can see the email attribute

Activity icon

Replied to Laravel Excel : How To Export Only Some Columns ?

@sti3bas

It exists in my model :

protected $appends=['tags','email','telephone','deals'];
(...)    
public function getEmailAttribute()
    {
        $this->loadMissing('teamleaderCompanyEmails');
       return $this->teamleaderCompanyEmails->where('type','=','primary')->implode('email',',');
    }

In my controller when I:

return TeamleaderCompany::get(['email']);

it returns :

Undefined column: 7 ERROR: column "email" does not exist LINE 1: select "email" from "teamleader_companies" ^ (SQL: select "email" from "teamleader_companies")
Activity icon

Started a new Conversation Laravel Excel : How To Export Only Some Columns ?

Hello :

I would like to export only some columns (email) :

the column email does not exists in table , but it's an accessor !(impossible to say ->get(["email"]))

Resources controller

 return Excel::download(new CompaniesExport($request->segmentId),'file_name.xls');

CompaniesExport :

 public function collection()
    {

        $this->sorting = 'id';
        $this->sortOrder = 'asc';

        if ($this->segmentId == 0) {
            $searchableTable = SearchableTable::where('name', 'like', 'teamleader_companies')->first();
            return TeamleaderCompany::orderBy($this->sorting, $this->sortOrder)->get();
        }
        (...)
    }
Activity icon

Started a new Conversation How To Select Accessor In Eloquent Results ?

Hello ,

In my model I defined one Accessor like :

    public function getEmailAttribute()
    {
        $this->loadMissing('teamleaderCompanyEmails');
       return $this->teamleaderCompanyEmails->where('type','=','primary')->implode('email',',');
    }

and it returns data without problem ,

In the controller: I would like to select this attribute using addSelect()

$companies =  TeamleaderCompany::select('name');
$companies->addSelect('email');
(...)

But it returns me :

Undefined column: 7 ERROR: column "email" does not exist 

How to select email in Eloquent results ?

thanks

Feb
21
1 month ago
Activity icon

Started a new Conversation How To Create A Constant Which Value Is From Get Axios Result In VueJS

Hello

I would like to initialize the constant value with the axios response data :

const mylist = .....
axios.get(`api/segment/searchable-columns/teamleader_companies`)
                    .then(response => {
                        /* here mylist  const data*/= response.data.searchable_columns;
                    });