Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

rjrocks

rjrocks

Member Since 2 Months Ago

Experience Points
370
Total
Experience

4,630 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
0
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 1
370 XP
Nov
21
2 days ago
Activity icon

Started a new Conversation Send WhatsApp Message Using Laravel

Hi Guys !

I am developing one application in laravel that provide feeds to users about their interested subject.

Other functionality is they receives feeds directly in email account and WhatsApp account.

Now, providing that email func. is done. But stuck at WhatsApp functionality.

Is anyone have any suggestion about any api that provides to send free messages, Please let me know.

Activity icon

Awarded Best Reply on Set “status = Sent” In Table After Email Sent

Just added foreach for updating and its done.

private function sendEmailToUser($userId, $feeds)
    {
        $user = User::find($userId);
        // Sets the status is equal to sent
        foreach($feeds as $feed){
            $affected = DB::table('feed_statuses')
                    ->where(['user_id'=> $userId , 'feed_id' => $feed['feed_id']])
                    ->update(['status' => 'sent']);
        }

        Mail::to($user)->send(new FeedEmailDigest($feeds));
    }
Activity icon

Replied to Set “status = Sent” In Table After Email Sent

Just added foreach for updating and its done.

private function sendEmailToUser($userId, $feeds)
    {
        $user = User::find($userId);
        // Sets the status is equal to sent
        foreach($feeds as $feed){
            $affected = DB::table('feed_statuses')
                    ->where(['user_id'=> $userId , 'feed_id' => $feed['feed_id']])
                    ->update(['status' => 'sent']);
        }

        Mail::to($user)->send(new FeedEmailDigest($feeds));
    }
Activity icon

Replied to Set “status = Sent” In Table After Email Sent

foreach ($feeds as $feed) {
	$data[$feed->user_id][] = $feed->toArray();
	$data[$feed->status][]='sent';
}
Activity icon

Replied to Set “status = Sent” In Table After Email Sent

I tried but not working? Can you just explain in descriptive ?

Activity icon

Started a new Conversation Set “status = Sent” In Table After Email Sent

My Application sends feeds to users as email. For that I have created one command name SendFeedEmails.php to send email.

Above command will get all feeds for today and stores user_id in array and execute private function named sendEmailToUser.

By that function all data will go FeedEmailDigest mailable class.

But I want to set status as sent in table named feed_statuses after the email sent to users.

1 ) SendFeedEmails.php(Command)

<?php

namespace App\Console\Commands;

use App\User;
use App\FeedStatus;
use App\Mail\FeedEmailDigest;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;

class SendFeedEmails extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'feed:emails';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send email notification to users about feeds.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // Get all feeds for today
        $feeds = FeedStatus::query()
            ->with(['feeds'])
            ->where('msg_date', now()->format('Y-m-d'))
            ->where('status', 'pending')
            ->orderBy('user_id')
            ->get();

        // Group by user
        $data = [];
        foreach ($feeds as $feed) {
            $data[$feed->user_id][] = $feed->toArray();
        }

        //dd($data);

        foreach ($data as $userId => $feeds) {
            $this->sendEmailToUser($userId, $feeds);

        }
        
        // Send email
        return 0;
    }

    private function sendEmailToUser($userId, $feeds)
    {
        $user = User::find($userId);
        Mail::to($user)->send(new FeedEmailDigest($feeds));
    }
}
2) FeedEmailDigest.php(Mail)

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class FeedEmailDigest extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    private $feeds;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($feeds)
    {
        $this->feeds = $feeds;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('emails.feed-digest')
            ->with('feeds', $this->feeds);
    }
}

3) feed_statuses(table)

id |user_id| feed_id| status| msg_date| count

Nov
16
1 week ago
Activity icon

Started a new Conversation Retrieving Records With _____________ Relationship ?

I have 5 tables.

  1. User tabel => This table stores the data of users.
  2. Exam table => This table stores the data of exams.
  3. Feeds table => This table stores the data of feeds.
  4. Exam_User_Pivot table => This table stores the data of users and exams means the user_id and exam_id.
  5. Exam_Feed_Pivot table => This table stores the data of exams and feeds means the exam_id and feed_id.

Now, I want to retrieve the no. of users per each feed ?

I have three models :

1) User model

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

    protected $primaryKey = 'uid';

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

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

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function exams()
    {
        return $this->belongsToMany(exam::class, 'exam_user', 'user_id', 'exam_id')->withTimeStamps();
    }
}
2) Exam model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class exam extends Model
{
    protected $primaryKey = 'eid';

    protected $fillable = [
        'exam_name',
    ];
}
3) Feed model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Feed extends Model
{
	protected $primaryKey = 'fid';

	protected $fillable = [
        'feed_type', 'title', 'description', 'feed_media', 'source',
    ];

    public function feedexams()
    {
    	return $this->belongsToMany(exam::class, 'exam_feed', 'feed_id', 'exam_id')->withTimeStamps();
    }
}

-> Users have many-to-many relationship with Exams.

-> Feeds have many-to-many relationship with Exams.

I want to retrieve the no. of users per each feed And I don't know which relationship can be use ?

Nov
04
2 weeks ago
Activity icon

Started a new Conversation Filter Out Unselected Fields From Table Via Many To Many Relationship In Laravel

In my project, User can select only one exam at the time of registration. But after logging into the site, user can add another exam. Now the problem is if user selected one perticular exam at the time of registration, he can not add that same exam again. In other words I want to show only unselected exam to that user which is not added by him/her. As I implemented many-to-many relationship in User model.

In very simple words : My need is to display contents from exams not having references to the table exam_user with user_id!=(Logged in user).

1) User.php

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

    protected $primaryKey = 'uid';

    public function exams()
    {
        return $this->belongsToMany(exam::class, 'exam_user', 'user_id', 'exam_id')->withTimeStamps();
    }
}
2) UsersController.php

class UsersController extends Controller
{
    
    public function __construct()
    {
        $this->middleware(['auth','verified']);
    }

    public function fetchExams()
    {
        $users = Auth::user();
        $exams_model = exam::all();
        return view('user.myExam', compact('users', 'exams_model'));
    }
}
3) myExam.blade.php

In this view user can see which exam is selcted by him/her in one table but I want to show user that exams which is not perticularly selected by that user.


@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-6">
            <h2>Your Exams</h2>
            @foreach ($users->exams as $exam)
                <p><kbd style="background-color: green; font-size: 16px;">{{$exam->exam_name}}</kbd></p>
            @endforeach
        </div>
        <div class="col-md-6">
            <form action="/addExam" method="POST">
                @csrf
                <h2>Add new exam</h2>
                @foreach ($exams_model as $ex)
                    <p><input type="checkbox" name="{{$ex->eid}}"> <kbd style="background-color: lightblue; color: black; font-size: 16px;">{{$ex->exam_name}}</kbd></p>
                @endforeach
            </form>
        </div>
    </div>
</div>
@endsection
4) Users Table

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('uid');
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('phone')->unique();
            $table->boolean('status')->default(0);
            $table->string('password');
            $table->string('profile_image')->default('default.jpg');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
5) Exams Table

class CreateExamsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('exams', function (Blueprint $table) {
            $table->increments('eid');
            $table->string('exam_name')->unique();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('exams');
    }
}
6) exam_user Table

This table stores user_id and exam_id as foreign key.
class CreateUserExamsPivotTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('exam_user', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('exam_id');
            $table->foreign('exam_id')->references('eid')->on('exams');
            $table->unsignedInteger('user_id');
            $table->foreign('user_id')->references('uid')->on('users');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('exam_user');
    }
}
Sep
22
2 months ago
Activity icon

Replied to Count Items With 'sold' Status

Just give any specific integer no for sold item in database (i.e. 1 or 2) and then fetch it from database and store all that array and after that count the no of items in array.

Sep
21
2 months ago
Activity icon

Replied to Project Suggestion

@saurav77 Thanks.

Activity icon

Replied to Project Suggestion

So, I can take socila media or e-commerce site or quiz app or any management site.

Further more I am not interested in CMS.

So, Guide me to choose any project.

Thank you.

Sep
20
2 months ago
Activity icon

Replied to Project Suggestion

@bobbybouwmann Yeah , but it's kindaa main project for my last year of University.

I don't have any intention to let you think on behalf of me but I got confused with lots of ideas suggested by my friends so I just wanna discuss it with you all.

Activity icon

Replied to Project Suggestion

Thanks both of you....Ideas are interesting.

But in my college, I alloted one guide so I have to report him with 4 or 5 idea and after discussing on them we conclude the best one.

So, give more ideas.

Thanks.

Activity icon

Replied to Project Suggestion

Happy with your reply.

But I need some idea perticulary on web development and also for big projects.

Activity icon

Started a new Conversation Project Suggestion

Hi Everyone !

Please suggest me some good ideas for web development.

Thank you.