Mrs_Beginner

Mrs_Beginner

Member Since 1 Year Ago

Quebec

Experience Points 2,240
Experience Level 1

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

29 Dec
6 months ago

Mrs_Beginner left a reply on Temporary Image Dos Not Exist

@REALRANDYALLEN - but when i use $imagefinalpath = request('image')->store('images'); every thing works for image sent by web form.

it is normal?

Mrs_Beginner started a new conversation Temporary Image Dos Not Exist

i have problem with uploading image of my product, i use below code for upload image

 //upload image

        $year = Carbon::now()->year;
        $month = Carbon::now()->month;
        $day = Carbon::now()->day;
        $imagePath = "/upload/images/{$year}/{$month}/{$day}";
        $originalname=$file->getClientOriginalName();
        $filename = md5($originalname. time()).$originalname;
        //check if file exists before
        if($filesystem->exists(public_path("{$imagePath}/{$filename}"))) {
            $filename = Carbon::now()->timestamp . "-{$filename}";
        }
        $file->move(public_path($imagePath) , $filename);
        $imagefinalpath=$imagePath.'/'.$filename;
        //finish uploading

i need $imagefinalpath to store it in my database.

when i use this code for upload image with Postman every thing is ok but when i am using web form an error happening like below The file AppData\Local\Temp\php1AD1.tmp does not exist laravel

my web form code is like below:

 <form role="form" action="{{ route('products.store') }}" method="post" enctype="multipart/form-data">
                    {{ csrf_field() }}
                            <input type="file" name="image" class="form-control" >

</form>

i do not know whats going on here!!!!

i did what someone said in below link but didnt worked for me!

https://github.com/laravel/framework/issues/12350#issuecomment-403194466

25 Dec
6 months ago

Mrs_Beginner left a reply on How To Return A Relation In Collection Or Map Returned Collection

@SNAPEY - thanks, so good tip for beginner like me.

Mrs_Beginner left a reply on How To Return A Relation In Collection Or Map Returned Collection

@D9705996 - Thank you for tips tips

i Will do the things you said.

Mrs_Beginner left a reply on How To Remove Item From Nested Collection

@D9705996 - thanks its worked, but you know why higher order function did not worked on my collection?

returned Json is like below (array of objects):

[
 {
                "id": 1,
                "name": "product1",
                "price": "1.00",
                "users": [
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                       
                    },
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                    },
                    {
                        "id": 4,
                        "name": "Wilson Rosenbaum",                       
                    },
                    {
                        "id": 5,
                        "name": "Wilson Rosenbaum",             
                    },
                  
                ]
            }
]

i`m so curious to find out why its happened. you have any good article about higher order functions in Laravel?

24 Dec
6 months ago

Mrs_Beginner left a reply on How To Remove Item From Nested Collection

@D9705996 - of course

user model like below:

 use Notifiable,HasApiTokens;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','mobile','image','active','suspend'
    ];
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token','api_token'
    ];

    public function products(){
        return $this->belongsToMany('App\Product');
    }


user migration like below:

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->nullable();
            $table->boolean('active')->default(false);
            $table->string('email')->unique();
            $table->string('password');
            $table->string('mobile')->nullable();
            $table->string('image')->nullable();
            $table->boolean('suspend')->default(false);
            $table->rememberToken();
            $table->timestamps();
        });
    }

and UserController for generate my collection is like below :


 public function user_products(){
        $user=User::findOrFail(auth()->user()->id);
        $user_products=$user->products()->distinct()->get();
        
        $res= $user_products->each->users->reject(function ($user) {
            return $user->id === 4;
        });
        return response($res);
}

Ok now product model is like below:

 protected $fillable=['name','detail','price','image'];

    //function to reffer to users
    public function users(){
        return $this->belongsToMany('App\User');
    }

and product migration :

 Schema::create('matches', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->text('detail');
            $table->string('image');
            $table->decimal('price', 15, 2);
            $table->timestamps();
        });
        Schema::create('match_user', function(Blueprint $table)
        {
            $table->integer('user_id')->unsigned()->index();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('NO ACTION');
            $table->integer('product_id')->unsigned()->index();
            $table->foreign('product_id')->references('id')->on('products')->onDelete('NO ACTION');
      
        });

i tried to simplify my code for more understanding...

Mrs_Beginner left a reply on How To Remove Item From Nested Collection

@D9705996 - i testes this one too, did not worked

Mrs_Beginner left a reply on How To Remove Item From Nested Collection

@D9705996 - i used but did not worked and collection is not changed after this code and no error happened

Mrs_Beginner left a reply on How To Remove Item From Nested Collection

@SERGIU17 - this one works for items in first level of collection i think but my collection is nested and this way cant works on that.

Mrs_Beginner started a new conversation How To Remove Item From Nested Collection

i have an problem with drop item from nested collections.

 {
                "id": 1,
                "name": "product1",
                "price": "1.00",
                "users": [
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                       
                    },
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                    },
                    {
                        "id": 4,
                        "name": "Wilson Rosenbaum",                       
                    },
                    {
                        "id": 5,
                        "name": "Wilson Rosenbaum",             
                    },
                  
                ]
            }

i want to find user in my collection that his/her id is 4 and delete him from collection. and my collection become something like below:

 {
                "id": 1,
                "name": "product1",
                "price": "1.00",
                "users": [
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                       
                    },
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                    },
                 
                    {
                        "id": 5,
                        "name": "Wilson Rosenbaum",             
                    },
                  
                ]
            }

as you see user that his/her id was 4 is deleted. i know that map or transform can do this but i do not know how i can reach id of user and delete that user from my collection,

Mrs_Beginner started a new conversation How To Return A Relation In Collection Or Map Returned Collection

hi i have 3 table users and products and product_user as pivot table (contains two column user_id and product_id). user can order an product more than once,

user model is like below:

 public function products(){
        return $this->belongsToMany('App\Product');
    }

product model is like below:

 public function users(){
        return $this->belongsToMany('App\User');
    }

Ok, when in my UserController i want to return all products of current user i do the following code:

$user=User::findOrFail(auth()->user()->id);
        $products_of_user=$user->products()->get();
        return response([
            'data' => [
                'info'=>$products_of_user,
            ],
            'status' => 'success',
        ]);

ok and returned Json is like below;

{
    "data": {
        "info": [
            {
                "id": 1,
                "name": "product1",
                "detail": "lorem ipsum is ... .",
                "price": "1.00",
                "created_at": "2018-12-17 16:48:12",
                "updated_at": "2018-12-17 16:48:12",
                "pivot": {
                    "user_id": 11,
                    "match_id": 1,
                },
                "users": [
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                        "active": 0,
                        "email": "[email protected]",
                        "Address": "Address 1",
                        "pivot": {
                            "match_id": 1,
                            "user_id": 3,
                        }
                    },
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                        "active": 0,
                        "email": "[email protected]",
                        "Address": "Address 2",
                        "pivot": {
                            "match_id": 1,
                            "user_id": 3,
                        }
                    },
                    {
                        "id": 4,
                        "name": "Wilson Rosenbaum",
                        "active": 0,
                        "email": "[email protected]",
                      "Address": "Address 12",
                        "pivot": {
                            "match_id": 1,
                            "user_id": 3,
                        }
                    },
                    {
                        "id": 5,
                        "name": "Wilson Rosenbaum",
                        "active": 0,
                        "email": "[email protected]",
                        "Address": "Address 16",
                        "pivot": {
                            "match_id": 1,
                            "user_id": 3,
                        }
                    },
                  
                ]
            }
        ]
    },
    "status": "success"
}

as you see in that object i have an array that called users, users that bought this product, this array exist in each product object.

as i said user can buy an product more than once (by different address). so in users array we can have Duplicate user by different address. so in this users array that exist in every product object, i need user that belongs to current logged in user. i need given Json change to below json (Suppose id of current logged in user is 3):

{
    "data": {
        "info": [
            {
                "id": 1,
                "name": "product1",
                "detail": "lorem ipsum is ... .",
                "price": "1.00",
                "created_at": "2018-12-17 16:48:12",
                "updated_at": "2018-12-17 16:48:12",
                "pivot": {
                    "user_id": 11,
                    "match_id": 1,
                },
                "users": [
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                        "active": 0,
                        "email": "[email protected]",
                        "Address": "Address 1",
                        "pivot": {
                            "match_id": 1,
                            "user_id": 3,
                        }
                    },
                    {
                        "id": 3,
                        "name": "Wilson Rosenbaum",
                        "active": 0,
                        "email": "[email protected]",
                        "Address": "Address 2",
                        "pivot": {
                            "match_id": 1,
                            "user_id": 3,
                        }
                    },      
                ]
            }
        ]
    },
    "status": "success"
}

i hope you understand what i need here. i know there is couple of ways to do this but i do not know how to handle them by mapping collection or create scope and how i can do this job.

17 Dec
6 months ago

Mrs_Beginner left a reply on ErrorException: Trying To Get Property Of Non-object

@REALRANDYALLEN - thanks my problem was inserting null IDs in DB by bad seeding, but i wonder why Ids was exist in table but Laravel couldn't recognize them.

Mrs_Beginner left a reply on ErrorException: Trying To Get Property Of Non-object

@MUNAZZIL - i did what you said but problem still remains and messages that their IDs is 12,13,14,15, ... , 20 is not assigned to user.

Mrs_Beginner left a reply on ErrorException: Trying To Get Property Of Non-object

@SERGIU17 - after applying this changes, its says

ErrorException: Undefined property: Illuminate\Database\Eloquent\Relations\BelongsTo::$name

Mrs_Beginner left a reply on ErrorException: Trying To Get Property Of Non-object

@alibayat @munazzil @mlaraei

i did some changes and something wierd happened. i did some changes in my message model like below: ( i deleted name from attribute because some users are null)


class Message extends Model
{
    protected $fillable = [
        'user_id',
        'conversation_id',
        'sender_name',
        'message'
    ];
    protected $hidden=['user'];
    protected $appends = ['sender_name'];
    //relation
  
    public function user()
    {
        return $this->belongsTo('App\User','id');
    }
    //attributes
    public function getSenderNameAttribute()
    {
        return $this->user->name; //error is happening in this line i do not know why
    }
}

and see what i saw returning result of $message=Message::all();

result is like below:

 "data": {
        "messages": [
            {
                "id": 1,
                "user_id": 4,
                "conversation_id": 8,
                "message": "lorem ipsum is non meanable text17",
                "created_at": null,
                "updated_at": null,
                "sender_name": {
                    "id": 1,
                    "name": "Creola Oberbrunner",
                    "active": 0,
                    "email": "[email protected]",
                    "mobile": "216-795-4382 x8825",
                    "image": "pyUROZokIqLKh2yFeOKzHk2XM11t7iwf2oTMqpXjatVz8YGNA4nWd2ygZ1JjHpNSMCqMsiOL8vMABGK4t2HlgV9uE5rkgA4FR5Dj",
                    "suspend": 0,
                    "created_at": "2018-12-15 22:49:55",
                    "updated_at": "2018-12-15 22:49:55"
                }
            },
            {
                "id": 16,
                "user_id": 15,
                "conversation_id": 5,
                "message": "lorem ipsum is non meanable text13",
                "created_at": null,
                "updated_at": null,
                "sender_name": {
                    "id": 16,
                    "name": null,
                    "active": 1,
                    "email": "[email protected]",
                    "mobile": null,
                    "image": null,
                    "suspend": 0,
                    "created_at": "2018-12-15 22:50:32",
                    "updated_at": "2018-12-15 22:50:32"
                }
            },
            {
                "id": 17,
                "user_id": 1,
                "conversation_id": 7,
                "message": "lorem ipsum is non meanable text2",
                "created_at": null,
                "updated_at": null,
                "sender_name": null
            },
            {
                "id": 18,
                "user_id": 12,
                "conversation_id": 5,
                "message": "lorem ipsum is non meanable text4",
                "created_at": null,
                "updated_at": null,
                "sender_name": null
            },
            {
                "id": 19,
                "user_id": 10,
                "conversation_id": 10,
                "message": "lorem ipsum is non meanable text3",
                "created_at": null,
                "updated_at": null,
                "sender_name": null
            },
            {
                "id": 20,
                "user_id": 1,
                "conversation_id": 4,
                "message": "lorem ipsum is non meanable text12",
                "created_at": null,
                "updated_at": null,
                "sender_name": null
            }
        ]
    },

as you see messages by id 1,2,3, ... ,16 have user id and "operator_name" but messages that have 17,18,19,20 IDs did not assigned to foreign key, why its happen?

Mrs_Beginner left a reply on ErrorException: Trying To Get Property Of Non-object

@ALIBAYAT - why this problem happen? how can i solve it?

Mrs_Beginner left a reply on ErrorException: Trying To Get Property Of Non-object

@MUNAZZIL - i cant understand that, you mean i use foreach loop for looping in users then showing thier messages?

 foreach ($users as $user){
            echo $user->messages();
        }

like this?

but i am returning Json response for application and this way cant sort messages by date created,

Mrs_Beginner left a reply on ErrorException: Trying To Get Property Of Non-object

@GURUR - its cool but i want to show messages in some thing like ChatRoom for specific user then i have to select messages from other users too,

my problem is showing getSenderNameAttribute() for shwing sender name in collections, when my collection have one message no error happen but more than one message throw error for me.

Mrs_Beginner left a reply on ErrorException: Trying To Get Property Of Non-object

@MLARAEI - its so weird for new bee like me, i have 20 message in messages table. i selected all of messages one by one by this code line in my controller $message=Message::find(1); to $message=Message::find(20);.

all the result showed correctly without error and sender name is showing for all of them, but when i want select them all at once with $messages=Message::all(); error will thrown,

i do not know why message model is assigned to a user in users table when i select one model but in collection error happen for me,

Mrs_Beginner started a new conversation ErrorException: Trying To Get Property Of Non-object

i have two table users and messages,

i want to show name of user that sent message when i get list of messages.

but i get error in line of Accessor in message model.

below is user migration:

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->nullable();
            $table->boolean('active')->default(false);
            $table->string('email')->unique();
            $table->string('password');
            $table->string('mobile')->nullable();
            $table->string('image')->nullable();
            $table->boolean('suspend')->default(false);
            $table->rememberToken();
            $table->timestamps();
        });
    }

and user model:

class User extends Authenticatable
{
    use Notifiable,HasApiTokens;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','mobile','image','active','suspend'
    ];
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token','api_token'
    ];

      public function messages(){
        return $this->hasMany('App\Message','user_id');
    }

}

and message migration is like below:

public function up()
    {
        Schema::create('messages', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->index()->nullable();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('NO ACTION');
            $table->text('message');
            $table->timestamps();
        });
    }

and below is message model:

class Message extends Model
{
    protected $fillable = [
        'user_id',
        'conversation_id',
        'sender_name',
        'message'
    ];
    protected $hidden=['user'];
    protected $appends = ['sender_name'];
    //relation
    public function conversation(){
        return $this->belongsTo('App\Conversation');
    }
    public function user()
    {
        return $this->belongsTo('App\User','id');
    }
    //attributes
    public function getSenderNameAttribute()
    {
        return $this->user->name; //error is happening in this line i do not know why
    }
}

and in message controller when i call one message every thing works fine (sender name is showing ) . like below code when i call it in controller:

        $message=Message::find(1);
   return response($message);

result is like below:

"message": {
            "id": 1,
            "user_id": 4,
            "message": "lorem ipsum is non meanable text17",
            "created_at": null,
            "updated_at": null,
            "operator_name": "Creola Oberbrunner"
        }

but when i want to select more than one message the error will thrown in 'return $this->user->name;' line that is in message model. and says 'ErrorException: Trying to get property of non-object'

like below code in controller:

        $messages=Message::all();
   return response($messages);

result is like below:

ErrorException: Trying to get property of non-object in file 

any one can help me to find the problem?

23 Nov
7 months ago

Mrs_Beginner left a reply on Show That Given Product Model Is Belongs To Logged In User Or Not

@REALRANDYALLEN - oh my god you saved my week, thank you so so much

Mrs_Beginner left a reply on Show That Given Product Model Is Belongs To Logged In User Or Not

i mean how can i use is_bought in collection for each product, i cant use with method, i think because 'is_bought' return boolean. is there any way or collection methods for my problem?

Mrs_Beginner left a reply on Show That Given Product Model Is Belongs To Logged In User Or Not

@AURAWINDSURFING - my product is like courses, i think i do not need orders table and order_Items my project have 20 course per term and user cant have them all, i think this pivot table (product_user) is enough, but still my real problem remains how to know which products belongs to logged in user or not

Mrs_Beginner started a new conversation Show That Given Product Model Is Belongs To Logged In User Or Not

i want load all products in collection for user, and in that list show user this product is belongs to him or not,

3 table i have,,,user table product table and product_user as pivot table,,,

in my product controller i want to load all product with below code:


$products=Product::withCount('users as number_of_user')->orderBy('created_at', 'desc')->paginate(10);

but i need some relationship function that in every loaded product says that product bought before by Auth user,

is there any way to define some function like below in Product model:

public function is_bought($userid){

$this->users->contains($userid);//return true if user bought this product before
}

and call this function in controller like below $products=Product::with(is_bought(auth->user()->id))->withCount('users as number_of_user')->orderBy('created_at', 'desc')->paginate(10);

?

22 Nov
7 months ago

Mrs_Beginner left a reply on Determinate Purchased And Non Purchased Products For Logged In User In Eager Loading Of All Products

@DALMA - OK, thanks ill do that, but then i have to put id of selected address in pivot table, then my original problem still not solved. i mean how can i get that Json format?

i dont wana exact format, i just need to get "Purchased_before_by_user" and "address_is_wrote" you know how can i get them?

"data": [
                {
                    "id": 4,
                    "name": "book",
                    "detail": "lorem.",
                    "price": "26000.00",
                    "created_at": "2018-11-20 07:09:55",
                    "Purchased_before_by_user": false  
                    "address_is_wrote":false  //if address column of pivot table is null
                },
                {
                    "id": 5,
                    "name": "book2",
                    "detail": "lorem.",
                    "price": "26000.00",
                    "created_at": "2018-11-20 07:09:55",
                    "Purchased_before_by_user": true
                    "address_is_wrote":true  //if address column of pivot table is not null
                }

                ]

Mrs_Beginner left a reply on Determinate Purchased And Non Purchased Products For Logged In User In Eager Loading Of All Products

@DALMA - Address is user address, in my project user can choose different address for her/his purchases. for this i placed address column in pivot table

21 Nov
7 months ago

Mrs_Beginner started a new conversation Determinate Purchased And Non Purchased Products For Logged In User In Eager Loading Off All Products

i want show all products to user and tell him which one is purchased before by her and which one is not, and tell her if she purchased an product and did not completed the address for receive the product.

some thing like below example in Json:

"data": [
                {
                    "id": 4,
                    "name": "book",
                    "detail": "lorem.",
                    "price": "26000.00",
                    "created_at": "2018-11-20 07:09:55",
                    "Purchased_before_by_user": false
                    "address_is_wrote":false
                },
                {
                    "id": 5,
                    "name": "book2",
                    "detail": "lorem.",
                    "price": "26000.00",
                    "created_at": "2018-11-20 07:09:55",
                    "Purchased_before_by_user": true
                    "address_is_wrote":true
                }

                ]

so here is my models:

users table:


$table->increments('id');
            $table->string('name')->nullable();
            $table->boolean('active')->default(false);
            $table->string('email')->unique();
            $table->string('password');

products table:

 Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->text('detail');
            $table->string('image');
            $table->decimal('price', 15, 2);

product_user table


 Schema::create('product_user', function(Blueprint $table)
        {
            $table->integer('user_id')->unsigned()->index();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('NO ACTION');
            $table->integer('product_id')->unsigned()->index();
            $table->foreign('product_id')->references('id')->on('matches')->onDelete('NO ACTION');
            $table->string('address')->nullable();

i think Nested Eager Loading maybe useful but i do not know how to define new relation in product model to nest it for showing purchased product with address and without address in product list that is showing to user,

06 Nov
8 months ago

Mrs_Beginner started a new conversation Validate To Input With Same Name That Belongs To Two Table

how can i validate this?

i have two id that one belongs to users table and other belongs to matches. how can i validate this? my code is like below:

        //validation data
        $validData=Validator::make($request->all(),[
            'user_id' => 'required|exists:users',
            'macth_id' => 'required|exists:matches',
            'user_reward' => 'required|integer',
            'user_rank' => 'required|integer',
        ]);

i know in validation, input name of Request should be same as column name but if i have two column with same name "id" that each one belong to one table? how can i tell Validate class that "id" input belongs to which table?

04 Nov
8 months ago

Mrs_Beginner left a reply on Select User Info From Pivot Table And Related Table

@Snapey ok its the only way?or best one?

like get number of matches that user won on them? is there any count method? to count pivot rows (that winner column is TRUE) without creating new model?

or i wana select all users with counting their winnings, how this one goes?

03 Nov
8 months ago

Mrs_Beginner started a new conversation Select User Info From Pivot Table And Related Table

i have 3 table and its many to many relationship users,matches,match_user as pivot table

users like below:

 Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->nullable();
            $table->boolean('active')->default(false);
            $table->string('email')->unique();
            $table->string('password');
            $table->string('mobile')->default(0);
            $table->string('image')->nullable();
            $table->boolean('suspend')->default(false);
            $table->rememberToken();
            $table->timestamps();
        });

matches like below:

 Schema::create('matches', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->text('detail');
            $table->string('reward');//REWARD OF THE MATCH
            $table->string('matchtype');//image type or video type:mean type of match that is image type or video type
            $table->string('image');
            $table->integer('price');
            $table->timestamp('expires_at');
            $table->boolean('expired')->default(false);
            $table->boolean('hot_match')->default(false);
            $table->timestamps();
        });

match_user pivot table like below:

 Schema::create('match_user', function(Blueprint $table)
        {
            $table->integer('user_id')->unsigned()->index();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('NO ACTION');
            $table->integer('match_id')->unsigned()->index();
            $table->foreign('match_id')->references('id')->on('matches')->onDelete('NO ACTION');
            $table->integer('user_rank')->default(0);
            $table->string('user_reward')->default(0);
            $table->string('file')->nullable();//the video or image that user send for match
            $table->string('introduce_video_link')->nullable();
            $table->boolean('winner')->default(false); //when its true,its mean user won in this match
        });

nad UserController is like below:

 public function show_user_profile(){
        $user=User::find(auth()->user());
        return response([
            'data' => [
                'info'=>$user,
            ],
            'status' => 'success',
        ]);
    }

i want JSON information like below:

name: david number of matches that was image type :3 number of matches that was video type :3 how much time user won:3

doesn't matter format of JSON i want this 3 info. can i get them in single query with laravel way? or i should do it with 3 query? Laravel have nay way in Eloquent way? or some thing like that for better performance maybe?

07 Oct
9 months ago

Mrs_Beginner started a new conversation Select Winners With Their Information From Pivot Table With Extra Fields Of Users And Matches Tables

hi i have 3 table users table

matches table

match_user pivot table with extra fields ('user_id','match_id','user_rank','user_reward') and pivot table code is like below :


     Schema::create('match_user', function(Blueprint $table)
        {
            $table->integer('user_id')->unsigned()->index();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('NO ACTION');
            $table->integer('match_id')->unsigned()->index();
            $table->foreign('match_id')->references('id')->on('matches')->onDelete('NO ACTION');
            $table->integer('user_rank')->default(0);
            $table->string('user_reward')->default(0);
        });

i wanna select all winners with their information and match information, who is winner? when "user_rank" or "user_reward" value is not equal to "0",

and user model code is like below:

class User extends Authenticatable
{
    use Notifiable,HasApiTokens;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','mobile','api_token','imageurl'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token','api_token'
    ];

    //function fo relating to matches
    public function matches(){
        return $this->belongsToMany('App\match');
    }
}

and match model code is like below:

class match extends Model
{
    protected $fillable=['name','detail','price','deadline','matchtype','reward','imageurl'];

    //function to reffer to users
    public function users(){
        return $this->belongsToMany('App\User');
    }
}

so now how can i get winner information? with match name and winner rank and reward?

i know laravel have some magic way to handle pivot tables with extra field but i dont what is it and how it works.

so how can i get winners info? and if you have any idea to make my code more optimize please leave a comment,thanks.

02 Sep
10 months ago

Mrs_Beginner left a reply on Face Recognition Package For Laravel Site

@Edris899 i saw it before, but it just an face detection package and cant recognize faces,

i need a recognizer

Mrs_Beginner started a new conversation Face Recognition Package For Laravel Site

HI im using KAIROS for face recognition in my personal application, but last week they said we cant offer more free plan for users and you should pay for our service(500$ per month for 1000 transaction or more),

and i dont need all of that feature with that count for my app i just need face recognition 20 time per day. and this free account was useful for me but they are removing it. and Microsoft is free just for 1 month(), and its not good for me too. is there any service or package (that could be handled on laravel) for face recognition?

17 Aug
10 months ago

Mrs_Beginner started a new conversation Use Same Request In Web Route And API Route With Different Controllers But Get Same Result

hi im using StoreImageRequest with below code:

class StoreImageRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        return [
            'martyr_id'=>'required',
            'imgurl'=>'image|mimes:jpeg,bmp,png|max:2000|required',
        ];
    }
}

and in upload controller of web.php route when i use it after successful upload return success upload page. its working fine

but when i use it in one of API controllers that belongs to api.php i should recive a json file with success message but this time success upload page is return again.

and when i removed from upload function of API controller, this time every thing worked fine. you know why its happen?

if you need more info just ask me.

16 Aug
11 months ago

Mrs_Beginner started a new conversation Best Way To Close Laravel Directories Except /public Folder

i founded two way to close all directories in shared host but i dont know which one is better (i mean better for performance or security or some thing else)

1- place all folders in next to public_html folder. and change index.php of Laravel public folder for Addressing new address of Laravel vendor folder and Laravel bootstrap folder.

2- place below code into index.php of Laravel public folder.


$app->bind('path.public',function(){
   return __DIR__;

is there any more way?which one is better?

08 Aug
11 months ago

Mrs_Beginner left a reply on How Many Way Exist To Add Custom Classes To Laravel 5.* ?

@36864 @Sergiu17

i want to send some data with $curl and use them in all Controllers that needed.

but i want to know when add class with facades or use Service Container or add them as file in app folder. which one is better for me now? which one has better performance? and is there any more ways? and what is differences between this ways?

Mrs_Beginner left a reply on How Many Way Exist To Add Custom Classes To Laravel 5.* ?

@Sergiu17

i mean like with facades or without it or other ways if exist,

sorry for bad question, question edited.

Mrs_Beginner started a new conversation How Many Way Exist To Add Custom Classes To Laravel 5.* ?

how many way is exist to add custom classes to laravel and what is differences between them?

29 Jul
11 months ago

Mrs_Beginner left a reply on Understand Collection Results From Elequent Relationship In Blade

@crnkovic yes your code is like my first code worked(post informations selected)...but i think i need good article about page builders and Elequents. before this i saw laravel 5.0 from scratch (jeffreyway) before 3 time but i cant understand this elequent relationship and query builders completely.

now i started see this course that you recommended. can i select user info at same query builder (User::find($id)->post()->where('title', 'cool')->get()) that post information's selected?

Mrs_Beginner left a reply on Understand Collection Results From Elequent Relationship In Blade

@frezno i did this but results didnt changed any thing still $user->firstname is null

Mrs_Beginner started a new conversation Understand Collection Results From Elequent Relationship In Blade

i want to show posts from a user in his profile...i did this but with some bugs (i can show posts but i cant show user first name) and i cant understand how it works... lets see my code first:

my post model is like below:

class post extends Model
{
    protected $fillable=['user_id','imgurl','name','detail'];

    public function user(){
        return $this->belongsToMany('App\User');
    }
}

then my user model is like below:

class user extends Model
{
    protected $fillable=['firstname','lastname','bio'];

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

and then function of my userController that call profile blade is:

 public function userposts($id){
        $user=User::find($id);
        return view(profile.posts',compact('user'));
     }

and finally part of my blade that shows posts and user name is like below code:

this profile belongs to mr/mrs {!! $user->firstname !!}
<tbody>
                @foreach($user->post as $post)
                    <tr>
                        <td> {!! $post->name !!}</td>
                        <td> {!! $post->detail !!}</td>
                        </td>
                    </tr>
                @endforeach
                </tfoot>

ok now i have some questions about this code... 1- in this blade i can see posts lists with their information but {!! $user->firstname !!} in top of blade dont show user first name, i think this line of code can show name but nothing appeared there,

2- if i change my userController code for showing user name to below code:

public function userposts($id){
        $user=User::find($id)->post();
        return view(profile.posts',compact('user'));
     }

but now some errors will happen that i cant understand them correctly its about collections but how they are creating... first error is like below

ErrorException (E_ERROR)
Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$firstname

this error points to {!! $user->firstname !!} and says its not exist in this collection. 2-1 how to fix this? or my controller code is not coreect?

2-2 if i delete {!! $user->firstname !!} from blade seccound error will happen is like below code.

ErrorException (E_ERROR)
Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$name

this one points to {!! $post->name !!}. i know this one is about collections too but i dont know how to fix it.

some one can explain to me how to handle this problem? how to understand this collection and show them in blade?

14 Jul
1 year ago

Mrs_Beginner started a new conversation How To Close Laravel Directores?

all directories like my resource directory is open and easily reachable by entering "MyDomin.com/resources/views/" in address bar. how i can i fix this one ?i have to close all of them? Laravel have something to do it or i have to use .htaccess in shared host?

Mrs_Beginner started a new conversation Best Practice For Handle Edit And Delete Requests When User Is Not Exist

i want to handle delete and edit requests. my edit functions in UserController.php is like below:


public function edit($id){
        $roles=Role::pluck('name','id');
        $user=User::findOrFail($id);
            return view('manageuser.edituser',compact('user','roles'));
    }
    

id of user will send by GET method. as you see i have findOrFail function to handle nonexistent users. but i can write another edit function like below code too:

public function edit($id){
        $roles=Role::pluck('name','id');
        $user=User::find($id);
        if ($user != null) {
            return view('manageuser.edituser',compact('user','roles'));
        } else {
            flash('user is not exist.')->important();
            return redirect('user/manage');
        }
    }

i handled nonexistent users with "if" statement. because when i use findOrFail function i dont know how to edit view that will return by this function for nonexistent users. it says "Sorry, the page you are looking for could not be found." or i have to use my if statements to handle?

and am i miss any more problem in edit function(except nonexistent users)? laravel will handle the other unexpected problems in requests?

Mrs_Beginner started a new conversation How To Run Laravel Home Page From Base Domain, In Shared Hosts

hi i want to run my Laravel site in "MyDomin.com" but i have to enter "MyDomain.com/public" in address bar of browser for getting home page... i have shared host.

how can i reach my Laravel home page by entering "MyDomin.com" in shared host?

and one more problem :) all directories like my resource directory is open and easily reachable by entering "MyDomin.com/resources/views/" in address bar. how i can i fix this one too?

06 Jul
1 year ago

Mrs_Beginner started a new conversation Remove GET Request URL After Running Action In Address Bar

i have a problem with URL in address bar when i delete or update some records.

for deleting records i send id in get request like

                       <a class="btn btn-outline" href="{{action('[email protected]',[$user->id]) }}" >

and the delete function will handle it.

public function delete ($id){
        $user=User::find($id);
        if ($user != null) {
            $user->roles()->detach();
            $user->delete();
            flash('user deleted.')->important();
            return $this->index();
        }
        flash()->success('user deleted before')->important();

        return $this->index();
    }

and index function is like this



    public function index(){

        $users=User::with('roles')->get();
        return view('manageuser.manageuser',compact('users'));
    }

after user deleted i will redirect to manage page, but in address bar i see the URL of deleting user like below

http://localhost/myapi/public/user/delete/4

but i should see below address when im in manage page:

http://localhost/myapi/public/user/manage

how can i see right address in address bar after deleting user with GET request?

03 Jul
1 year ago

Mrs_Beginner left a reply on Add New Column To Existing Table

@Yorki thank you so much, after i read your answer again i found my stupidity. thank you

Mrs_Beginner left a reply on Add New Column To Existing Table

@Yorki yes i checked it was not exist in database but im sure this table was created. then i tried to recreate this table and when i run ~~~ php artisan make:migration create_meta12meta_table --table="meta12meta" ~~~ the migration file that will add is like below code.

class CreateMeta12metaTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('meta12meta', function (Blueprint $table) {
            //
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('meta12meta', function (Blueprint $table) {
            //
        });
    }
}

as you see ~~~ Schema::table ~~~ means this table created before and saved somewhere. but table didnt created in database :| . i dont know whats wrong here. then i decided to create new table with different name. i created new migration by running this command ~~~ php artisan make:migration create_metakeys_table --table="metakeys" ~~~ but when i ran ~~~ php artisan migrate ~~~ for migration it says

  [Illuminate\Database\QueryException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mapi.metakeys' doesn't exist (SQL: alter table `metakeys` add `id` int unsigned not null auto_increment
  primary key, add `created_at` timestamp null, add `updated_at` timestamp null)

  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mapi.metakeys' doesn't exist

  [PDOException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mapi.metakeys' doesn't exist

i dont know whats wrong here...i had 5 table before this new table,some data stored in old tables but i cant add new table or edit columns...