ethar

Member Since 1 Year Ago

Experience Points
17,100
Total
Experience

2,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
115
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.

  • Community Pillar

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

Level 4
17,100 XP
Apr
22
2 weeks ago
Activity icon

Replied to When Field =1 Select Value From Another Table

@maaz thx, but noti_to is field in db

i try to do this but not working


            ->when('noti_to',3,function ($q) use ($user_id){
                $q->orWhere('user_id',$user_id);
            })
Activity icon

Started a new Conversation When Field =1 Select Value From Another Table

i have notification table, (id, txt, noti_to, user_id)

i want to get notifications if(noti_to=1, noti_to=2, but if noti_to=3 i want to select where user_id=$id);

    public function notifications($user_id,$gender){
        return showNotificationResource::collection(Notification::select(
            'id',
            'title',
            'body',
            'created_at'
        ))
            ->where('noti_to',1)
            ->orWhere('noti_to',$gender)
            ->orWhere('noti_to', 3)// if noti_to=3, how to add where('user_id',$user_id)
            ->get();
    }

how to add where('user_id',$user_id) if noti_to=3

Apr
15
3 weeks ago
Activity icon

Started a new Conversation Groub By Article Title

i try to get articles, and some articles have dublicated title i want to groub by title


        $articles=Article::select(
            'id',
            'img',
            'created_at',
            'title_ar',
        )->groupBy('title_ar')->limit(6)->get();

but i got this error


SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mhpss.articles.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select `id`, `img`, `created_at`, `title_ar` from `articles` group by `title_ar` limit 6)
Apr
10
4 weeks ago
Activity icon

Started a new Conversation Mark Check Box Checked, Pivot Table

i have author table, books table, and pivot table author_book. data saved successfully and displayed successfully.

but in edit i want to get all books and if author have spesific book must marked as checked

i try this code but not work

//eloquent
        $author=Author::with('Books')->findOrFail(1);
        $books=Book::select('id','name')->get();
        return view('author',compact('author','books'));

//blade

@foreach($books as $book)
       <div class="form-check">
          <input  type="checkbox" {{ in_array($author->books->id,$book->id) ? "checked" : "" }} value="{{ $book->id }}" >
          <label >{{ $book->name }}</label>
      </div>
@endforeach
Apr
06
1 month ago
Activity icon

Started a new Conversation Get Count Of <p> Tag In Text

how can add some data after paragraph number n in laravel blade

Mar
30
1 month ago
Mar
29
1 month ago
Activity icon

Replied to Open Url Without Using Return

no i want to open url in sendMsg function without using return

Activity icon

Started a new Conversation Open Url Without Using Return

i use this way to open external url and send msg


    public function sendMsg($dialCode, $phone, $pin)
    {
        $to_phone_number = $dialCode . $phone; // who are you sending to?
        $url = "http://sms.htd.ps/API/SendSMS&to=".$to_phone_number."&msg=Your Code is $pin";
        return Redirect::intended($url);
    }

i want to open url without using return cause i want to go to next step


if ($user) {
        $this->sendMsg($request->country_dial_code, $request->phone, $user->pin_code);
        return new showUserResource($user);
 }
Mar
23
1 month ago
Activity icon

Replied to Get Category With Last 3 Product Add

no i got last 3 books for last author, not last 3 book for every author

Activity icon

Replied to Get Category With Last 3 Product Add

->latest

cant determinant number of books, it get all books

Activity icon

Started a new Conversation Get Category With Last 3 Product Add

i have authors table, and books table every author have many books

i want to get authors with last 3 book add

i try this but i got books for last author

    public function index(){
        $authors=Author::with(['book' => function ($q) {
            $q->select('id', 'author_id','title')
                ->orderby('id', 'DESC')->take(3);
        }])->get();
        return $authors;
    }

relation ship

    public function book(){
        return $this->hasMany('App\Models\Book','author_id');
    }
Mar
19
1 month ago
Activity icon

Started a new Conversation File Upload With Filepond

i use filepond to upload file

field name is avatar

file uploaded successfully

but when send data to the controller and make dd($request->avatar)

i got this data , so i cant reach file name

""" Picture.png<script t ▶

Sfdump = window.Sfdump || (function (doc) { var refStyle = doc.createElement('style'), rxEsc = /([.*+?^${}()|\[\]\/\\])/g, idRx = /\bsf-dump-\d+-ref[01 ▶ but when make return $request->avatar i get file name Picture.png
Mar
14
1 month ago
Activity icon

Replied to Routes Not Working After Run Route:clear

solved after run

Artisan::call('route:clear');

but how can i make a cache route in shared host

Activity icon

Replied to Routes Not Working After Run Route:clear

@automica nothing exist , empty file

Activity icon

Started a new Conversation Routes Not Working After Run Route:clear

i run this command on my shared Host

    public function cacheControll(){
        Artisan::call('cache:clear');
        Artisan::call('config:clear');
        Artisan::call('config:cache');
        Artisan::call('view:clear');
        Artisan::call('route:clear');
        Artisan::call('route:cache');
        return 'done';
    }

but after run it all routes not work, but redirect me to 404 error page.

Mar
13
1 month ago
Activity icon

Replied to Order By (asc, Desc) Not Working In Subquery

@michaloravec your are correct, but why subquery not working

Activity icon

Started a new Conversation Order By (asc, Desc) Not Working In Subquery

i try to get users order by phone number, the problem is (asc,desc) not working but get the same order

the relation is hasOne


        $users=User::query()
            ->orderBy(Phone::select('phone')
                ->whereColumn('user_id','users.id')
                ->orderBy('phone','DESC')
                ->take(1)
            )
            ->with('phone')
            ->get();
Mar
11
1 month ago
Activity icon

Started a new Conversation Help To Set Cache In Composer For Appserviceprovider Values?

please how can make cache for this code

View::composer(['front.index','front.history'],function($view){
            $view->with('education',Education::select(
                'title_' . LaravelLocalization::setLocale() . ' as title',
                'tags_' . LaravelLocalization::setLocale() . ' as tags',
                'text_' . LaravelLocalization::setLocale() . ' as text',
                'from_date',
                'to_date'
            )->where('active',1)->get());
        });
Mar
10
1 month ago
Activity icon

Replied to Is There A Way To Set Cache For Appserviceprovider Values?

thanks @michaloravec can you help me to cache composer

        View::composer(['front.index','front.history'],function($view){
            $view->with('education',Education::select(
                'title_' . LaravelLocalization::setLocale() . ' as title',
                'tags_' . LaravelLocalization::setLocale() . ' as tags',
                'text_' . LaravelLocalization::setLocale() . ' as text',
                'from_date',
                'to_date'
            )->where('active',1)->get());
        });
Activity icon

Started a new Conversation Is There A Way To Set Cache For Appserviceprovider Values?

i have this share in appServiceProvider.php

View::share('settings', Settings::select( '' . $name_site . ' as site_name', ''.$desc_site.' as site_desc', ''.$keyword.' as site_keyword')->first());

how can make cache?

Activity icon

Started a new Conversation Pass Parameter Via Cache Function

hi i try to cache data,

        $snipp = cache()->remember('single_snipp',60 * 60 *60,function (){
            return Snippet::select(
                'text_' . LaravelLocalization::setLocale() . ' as text',
            )->where('id',$id)
                ->firstOrFail();
        });

but i got an error cause i must pass $id to where, how can i pass id?

Feb
26
2 months ago
Activity icon

Started a new Conversation Make Another Query If Field Have Specific Value

i have field named arrive_location arrive location have just two value (exist, new)

in eloquent


        $orders = Orders::select('id', 'users_id', 'arrive_location')
            ->with('users:id,fname,lname,telno')

i want if arrive_location == new, to make another query to get data


UserOrderArriveAddress::select('order_id','addresse_id');
Feb
25
2 months ago
Activity icon

Started a new Conversation Recive Post Values From Another Website

i receive a POST Request from another website, but the problem in CSRF Token, I exception in VerifyCsrfToken but not work

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'responseCredit'
    ];
}

responseCard is a function/URL where I must read post data

any help

Jan
20
3 months ago
Activity icon

Replied to Auto Submit Form

@bugsysha thanx solved


    <form method="post" name="paymentForm" id="paymentForm" action="{{ $actionTo }}">
        <input type="hidden" name="Version" value="{{ $version }}"><br>
        <input type="hidden" name="MerID" value="{{ $merchantId }}"><br>
    </form>
    <script type="text/javascript">
                document.forms["paymentForm"].submit();
    </script>
Activity icon

Replied to Auto Submit Form

@bugsysha Thanks It must be redirected me to the payment page with form input values,

your way not working

Activity icon

Started a new Conversation Auto Submit Form

i want to auto submit form when visit page, but the following code is not working, plz any help

<form method="post" onload="autoSubmit();" name="paymentForm" id="paymentForm" action="{{ $actionTo }}">
        <input type="hidden" name="Version" value="{{ $version }}"><br>
        <input type="hidden" name="MerID" value="{{ $merchantId }}"><br>
        <input type="hidden" name="AcqID" value="{{ $acquireId }}"><br>
    </form>
    <script type="text/javascript">

            function autoSubmit() {
                document.forms["paymentForm"].submit();
            }

    </script>
Activity icon

Started a new Conversation Redirect To Controller With Parameter And Read Parameter

i want to redirecto to another controller & and read the parameter from reciver controller

redirect

if($request->payament_method == 4){
      return \Redirect::route('creditCard',['oid'=>$order->id]);
 }

web.php

Route::get('/creditCard', '[email protected]')->name('creditCard');

PayamentController

class PayamentController extends Controller
{
    public function creditCard(){
	//How can read paramete here
	}
}
Jan
17
3 months ago
Activity icon

Replied to Two Column As Unique Value

@tray2 thanks, can you help me, how we can do this in validation

Jan
16
3 months ago
Activity icon

Started a new Conversation Two Column As Unique Value

i have this table

users=>name, country_code, phone_number

how can make (country_code, phone_number) as unique, in migration and validation.

Jan
11
3 months ago
Activity icon

Replied to Custome Error Message (Request Validation)

when remove unique:users,phone',

its return hellow kitty

but when add unique:users,phone', its return index page

Activity icon

Replied to Custome Error Message (Request Validation)

i copy your code and put it on my code

but when add unique:users,phone

its return default laravel index page

Activity icon

Replied to Custome Error Message (Request Validation)

@newbie360

still not working validation for phone

'phone'=>'required|min:10|max:15|unique:users,phone',

users DB

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('phone')->unique();
        });
    }
Activity icon

Started a new Conversation Custome Error Message (Request Validation)

I make this request file validation

class RegisterRequest extends FormRequest {

    public function authorize() {
        return true;
    }

    public function rules() {
        return [
            'name'=>'required',
            'phone'=>'required|unique|min:10|max:15',
            'gender'=>'required|integer',
            'marital_status'=>'required|integer',
            'birth_date'=>'required|date',
        ];
    }

    public function messages(){
        return [
            'name.required'=>'الرجاء إدخال الإسم',
            'phone.required'=>'الرجاء إدخال رقم الهاتف',
            'phone.unique'=>'رقم الهاتف موجود مسبقاً، بإمكانك تسجيل الدخول بإستخدام رقم الهاتف.',
            'phone.min:10'=>'الرجاء إدخال رقم هاتف صحيح',
            'phone.max:15'=>'الرجاء إدخال رقم هاتف صحيح',
            'gender.required'=>'الرجاء إختيار الجنس',
            'marital_status.required'=>'الرجاء إختيار الحالة الإجتماعية',
            'birth_date.required'=>'الرجاء إدخال تاريخ الميلاد',
        ];
    }
}

in eloquent my code is, i use RegisterRequest instead of Request

    public function store(RegisterRequest $request)
    {
        $user= new User();
        $user->name = $request->name;
        $user->phone = $request->phone;
        $user->gender = $request->gender;
        $user->martial_status = $request->marital_status;
        $user->birth_date = $request->birth_date;
        $user->pin_code = mt_rand(100000, 999999);
        $user->save();
        if($user){
            return $this->successMsg($user);
        }
    }

but custom error message not returned, I got default MySQL error msg, not messages defined in RegisterRequest.

e.g if try to register with an existing phone number I got this MySQL error

Integrity constraint violation: 1062 Duplicate entry '0599888999' for key

not custome error

Jan
09
3 months ago
Activity icon

Started a new Conversation Read Data And Insert It To Db

I work with API, when printing $request echo $request , i got this

flutter: POST /api/confirmPurchase HTTP/1.1
Accept-Encoding: gzip
Content-Length:  460
Content-Type:    text/plain; charset=utf-8
Host:            www.mhpss.test
User-Agent:      Dart/2.10 (dart:io)
{
   "data":[
      {
         "id":21,
         "pid":3,
         "artitle":"hand bag",
         "price":20,
         "size":" LG",
         "color":"#DFA590",
         "pic":"/images/products/bag_1_3.png",
         "qty":1
      },
      {
         "id":20,
         "pid":3,
         "artitle":"tshirt",
         "price":20,
         "size":" XS ",
         "color":"#8B8586",
         "pic":"/images/products/bag_1_3.png",
         "qty":1
      },
   ]
}

when try to print data echo $request->data i got nothing.

any way to read this data and insert it to db.

Jan
04
4 months ago
Activity icon

Started a new Conversation 1055 Expression #1 Of SELECT List Is Not In GROUP BY Clause And Contains Nonaggregated Column

i have chat_msgs table it contains ( body, type, from_id, to_id, )

i want to group by from_id, my Eloquent

    public function index()
    {
        $chatMsgs=ChatMsg::select('id','body','from_id','to_id')
            ->where('to_id',Auth()->user()->id)
            ->with('user:id,name')
            ->groupBy('from_id')
            ->get();
        return $chatMsgs;
    }

but I got this error SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mhpss.chat_msgs.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select id, body, from_id, to_id from chat_msgs where to_id = 1 group by from_id)

I try to use

public function index()
{
    $chatMsgs=ChatMsg::select('id','body','from_id','to_id')
        ->where('to_id',Auth()->user()->id)
        ->with('user:id,name')
        ->groupBy('from_id','id')
        ->get();
    return $chatMsgs;
}
but I got all record without groubing
Dec
29
4 months ago
Activity icon

Started a new Conversation Mutators Not Work

i have this mutator, check if value is True , insert 1 to db, if not insert 0

    public function setHiddenNameAttribute($value)
    {
        if($value == True){
            $this->attributes['hidden_name'] = 1;
        }else if($value == False){
            $this->attributes['hidden_name'] = 0;
        }
    }

eloquent

$ques->hidden_name = $request->display_name;

but aways 1 is inserted to db, eloquent ignore mutators

Dec
17
4 months ago
Activity icon

Replied to Get Data From Another Model

@tykus i got this error

Trying to get property 'day' of non-object (View: /Library/WebServer/Documents/mhpss/resources/views/admin/clinics/indexclinics.blade.php)

Activity icon

Started a new Conversation Get Data From Another Model

i have this model

class Clinic extends Model
{
    public function clinkDay(){
        return $this->hasOne('App\Models\ClinkDay');
    }
}

and another model to specify days of clinic

class ClinkDay extends Model
{
    public function clinic(){
        return $this->belongsTo('App\Models\Clinic');
    }
}

in eloquent

        $clinics=Clinic::select('id','title','admin_id','active','doctor_id','created_at')
            ->with('admin:id,name')
            ->with('doctor:id,name_ar,major_ar,thumb')
            ->with('clinkDay:clinic_id,day,from,to')
            ->orderBy('id','DESC')
            ->paginate(13);

in eloquent everything is ok,

but in Clinik Model I want to reach the day field that exist in ClinkDay

i try to use this

    public function getDay()
    {
        return $this->day;
    }

but doesn't work

any way to reach day field in clinkDay

Nov
30
5 months ago
Activity icon

Replied to Get Specific Fields From Laravel API Resource Collection

@vincent15000 not working i got this error ErrorException: Non-static method Illuminate\Database\Eloquent\Model::only()

Activity icon

Started a new Conversation Get Specific Fields From Laravel API Resource Collection

i have this CatResource

return [
    'id' => $this->id,
    'title' => $this->title,
    'desc' => $this->desc,
    'active' => $this->getActive(),
    'admin'=> $this->admin,
    'tags'=> $this->tags,
    'created_at' => $this->created_at->toDateString(),
];

in query i use

return CatResource::collection(
    Cat::with('admin:id,name')
        ->orderBy('id','DESC')
        ->paginate(13)
);

i get this array

{
    "data": [
        {
            "id": 22,
            "title": "Omnis quia nihil lab",
            "desc": "Quibusdam tempore q",
            "active": "<span class=\"text-success\">مفعل</span>",
            "admin": {
                "id": 1,
                "name": "إيثار"
            },
            "tags": "Ullamco qui enim des",
            "created_at": "2020-11-28"
        },
    ]
}

until know every thing is ok. but in some case i wat to return just

{
    "data": [
        {
            "id": 22,
            "title": "Omnis quia nihil lab",
        },
    ]
}

the question of how can do that get just a specific field not all key in the resource file, without creating a new resource file

Nov
29
5 months ago
Activity icon

Started a new Conversation Update Select Box Vue Js

i have this active value in vue js

data(){
        return{
            fields:{
                active:'',
            }
        }
    },

i want if active = 1 to print this

<select class="form-control" required="" v-model="fields.active">
          <option value="1">active</option>
           <option value="0">in active</option>
</select>

but if active = 0

 <select class="form-control" required="" v-model="fields.active">
              <option value="0">in active</option>
              <option value="1">active</option>
</select>
Nov
28
5 months ago
Activity icon

Replied to Error In Laravel API Resource

@michaloravec after refactoring i got this error

BadMethodCallException
Call to undefined method App\Models\Admin::mapInto()
http://www.vuecms.test/api/cats
Activity icon

Started a new Conversation Error In Laravel API Resource

i want to get cat with admin who create the cat

in catController

    public function index()
    {
        $cats=Cat::with(['admin.cat'])->get();
        return CatResource::collection($cats->paginate(13));
    }

in catModel

    public function admin(){
        return $this->belongsTo('App\Models\Admins');
    }

in adminModel

    public function cat(){
        return $this->hasMany('App\Models\Cat');
    }

in catResource

    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'desc' => $this->desc,
            'active' => $this->getActive(),
            'admin'=> AdminResource::collection($this->whenLoaded('admin')),
            'created_at' => $this->created_at,
        ];
    }

in adminResource

    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'cat' => CatResource::collection($this->whenLoaded('cat')),
        ];
    }

but i got this error

Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'cats.admins_id' in 'where clause' (SQL: select * from `cats` where `cats`.`admins_id` in (1))

why in select cats.admins_id it must be cats.admin_id

i reanamed admins Model to admin bu i got this error

BadMethodCallException
Call to undefined method App\Models\Admin::mapInto()
http://www.vuecms.test/api/cats
Nov
24
5 months ago
Activity icon

Replied to Vue Js With Laravel 8 Route Error

same problem, i use laravel 8

Activity icon

Started a new Conversation Vue Js With Laravel 8 Route Error

i use apiResource to submit data but i got an error

in api.php

Route::apiResource('posts', PostController::class);

in vuejs file create.vue

    methods:{
        submitData(){
            axios.post('api/posts',this.fields).then(res=>{
                this.$router.push('/');
            });
        }
    }

but i got this error

{message: "", exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…}
exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
file: "/Library/WebServer/Documents/LaraVue/vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php"
line: 43
message: ""
Activity icon

Replied to Register Component In Vue.js

@rodrigo.pedra another question how can register component locally