KalimeroMK

KalimeroMK

Member Since 7 Months Ago

Experience Points
15,860
Total
Experience

4,140 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
124
Lessons
Completed
Best Reply Awards
1
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 4
15,860 XP
Jun
20
2 weeks ago
Activity icon

Started a new Conversation Array To String Conversion

this seeder throws Array to string conversion don't understand why

<?php

use App\Models\User;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Spatie\Permission\PermissionRegistrar;

class RolesAndPermissionsSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */

    public function run()
    {
        // Reset cached roles and permissions
        app()[PermissionRegistrar::class]->forgetCachedPermissions();

        // create permissions
        $permissions = [
            'settings-list',
            'settings-create',
            'settings-edit',
            'settings-delete',
            'categories-list',
            'categories-create',
            'categories-edit',
            'categories-delete',
            'tags-list',
            'tags-create',
            'tags-edit',
            'tags-delete',
            'user-list',
            'user-create',
            'user-edit',
            'user-delete',
            'role-list',
            'role-create',
            'role-edit',
            'role-delete',
            'post-list',
            'post-create',
            'post-edit',
            'post-delete',
            'ad-list',
            'ad-create',
            'ad-edit',
            'ad-delete'
        ];


        foreach ($permissions as $permission) {
            Permission::create(['name' => $permission]);
        }

        // create roles and assign existing permissions
        $role1 = Role::create(['name' => 'writer']);
        $role1->givePermissionTo([
            'tags-list',
            'tags-create',
            'tags-edit',
            'tags-delete',
            'post-list',
            'post-create',
            'post-edit',
            'post-delete'
        ]);

        $role2 = Role::create(['name' => 'admin']);
        $role2->givePermissionTo([
            'settings-list',
            'settings-create',
            'settings-edit',
            'settings-delete',
            'categories-list',
            'categories-create',
            'categories-edit',
            'categories-delete',
            'tags-list',
            'tags-create',
            'tags-edit',
            'tags-delete',
            'user-list',
            'role-list',
            'post-list',
            'post-create',
            'post-edit',
            'post-delete'
        ]);

        $role3 = Role::create(['name' => 'super-admin']);
        $role3->givePermissionTo(Permission::all());

        // create demo users
        $user = Factory(User::class)->create([
            'name' => 'Example User',
            'email' => '[email protected]',
        ]);
        $user->assignRole($role1);

        $user = Factory(User::class)->create([
            'name' => 'Example Admin User',
            'email' => '[email protected]',
        ]);
        $user->assignRole($role2);

        $user = Factory(User::class)->create([
            'name' => 'Example Super-Admin User',
            'email' => '[email protected]',
        ]);
        $user->assignRole($role3);
    }

}
Jun
13
3 weeks ago
Activity icon

Replied to How To Send Error Notification To Slack

Already done that and I broke my code to show undefined variable but nothing shows on slack I have install laravel/slack-notification-channel package

Jun
12
4 weeks ago
Activity icon

Started a new Conversation How To Send Error Notification To Slack

I traying to send error notification to slack channel, I create SLACK_HOOK to the channel add slack to 'channels' => ['single', 'slack'], to the logging.php file but nothing comes to slack channel when error pups up tray with

Route::get('/', function () {
    Log::error("Error");
});

like laracast video but no joy

Jun
10
1 month ago
Activity icon

Started a new Conversation Problem With Save Image Name

traying to save image name in the database but listed the name is saving temporal address my code


    /**
     * @param Store $request
     * @return RedirectResponse
     */
    public function store(Store $request)
    {

        $request->featured_image = $this->verifyAndStoreImage($request);
        $post = Post::create([$request->all()]);
        $post->tags()->attach($request->tags);
        $post->categories()->attach($request->category);

        Session::flash('success_msg', trans('messages.post_created_success'));
        return redirect()->route('posts.edit', $post);
    }

when I

dd(  $request->featured_image)

it shows the name

^ "z5M9ifu9Qvz6ikB.jpg"

but on save is saving

/tmp/php7PhZcJ
Jun
08
1 month ago
Activity icon

Started a new Conversation Remove Duplicate Row In Table

Have a database with tags table with over 200k records and more than 80% are duplicate so I need to delete them try this SQL code but no joy

DELETE t1 FROM tags t1
             INNER JOIN tags t2
             WHERE t1.id > t2.id AND t1.slug =t2.slug

after 4 h of running no data is deleted

table structure is id/title/slug

Jun
02
1 month ago
Activity icon

Started a new Conversation Create Tags In On Flay

Currently when I want to add tags in my posts I have to go to my tags page and create them then go to my post create page and add them to my post by multiple input field and so far everything is working fine.

But what if I want to make my tag system works like WordPress? means I write my tags in my multiple fields in my post create page and if that tag already exists just will be added and if not as new tag will be saved in database and in that post as well

May
22
1 month ago
Activity icon

Replied to Validate Parent_id In Request Class

my route is

    Route::resource('categories', 'CategoryController');

can you give my an example

Activity icon

Replied to Validate Parent_id In Request Class

use resource routes and no joy on your examples all return null

Activity icon

Started a new Conversation Validate Parent_id In Request Class

Have edit category method and want to validate the parent_id is not the same as the category id to prevent category become a parent of itself. Try this code but no joy

class Update extends FormRequest
{
    use CanAuthorise;

    /**
     * @var mixed
     */
    private $id;

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|string|255',
            'parent_id' => 'different:' . $this->id,
    //or 'parent_id' => 'different:id' 
        ];
    }
}
Apr
30
2 months ago
Activity icon

Awarded Best Reply on Save Nested Array In Database

        foreach ($json as $items) {
            $post = new Post();
            $post->title = $items->title;
            $post->description = $items->description;
            $post->save();
        }

just save all the data form nested array

Activity icon

Replied to Save Nested Array In Database

        foreach ($json as $items) {
            $post = new Post();
            $post->title = $items->title;
            $post->description = $items->description;
            $post->save();
        }

just save all the data form nested array

Apr
26
2 months ago
Activity icon

Replied to Trying To Get Property 'show_in_menu' Of Non-object

App\Models\Category {#587 ▼
  #table: "categories"
  #fillable: array:11 [▶]
  #connection: "mysql"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:14 [▼
    "id" => 2
    "name" => "Патувањаa"
    "slug" => ""
    "show_in_menu" => 1
    "show_in_sidebar" => 1
    "show_in_footer" => 1
    "seo_keywords" => null
    "seo_description" => null
    "parent_id" => null
    "_lft" => 1
    "_rgt" => 2
    "created_at" => "2020-04-25 12:05:41"
    "updated_at" => "2020-04-25 12:05:41"
    "show_on_home" => 0
  ]
  #original: array:14 [▶]
  #changes: []
  #casts: []
  #classCastCache: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▶]
  #pending: null
  #moved: false
}
Activity icon

Started a new Conversation Trying To Get Property 'show_in_menu' Of Non-object

controller

public function edit(Category $category)
    {
        return view('admin.categories.edit', compact('category'));
    }

view

<div class="form-group">
        <label for="title" class="col-sm-3 control-label">{{trans('messages.title')}}</label>

        <div class="col-sm-8">
            <input id="title" class="form-control" type="text" name="name"
                   placeholder="{{trans('messages.enter_category_title')}}"
                   value="{{ old('title', $category->title ?? null) }}"/>
        </div>
    </div>
<div class="form-group">
    <div class="col-md-offset-3 col-md-8">
        <label>
            {!! Form::checkbox('show_in_menu', 1, ($category->show_in_menu ==1 ? true:null), ['class' => 'field']) !!}
            {{trans('messages.show_category_in_menu')}}
        </label>
    </div>
</div>

and if tray

<div class="form-group">
        <label for="title" class="col-sm-3 control-label">{{trans('messages.title')}}</label>

        <div class="col-sm-8">
            <input id="title" class="form-control" type="text" name="name"
                   placeholder="{{trans('messages.enter_category_title')}}"
                   value="{{ old('title', $category->title ?? null) }}"/>
        </div>
    </div>
@endif
<div class="form-group">
    <div class="col-md-offset-3 col-md-8">
        <label>
            {!! Form::checkbox('show_in_menu', 1, ($category['show_in_menu '] ==1 ? true:null), ['class' => 'field']) !!}
            {{trans('messages.show_category_in_menu')}}
        </label>
    </div>
</div>

getting error undefined index: show_in_menu

Apr
20
2 months ago
Activity icon

Replied to User Profile Pages

my bed miss understand you just need to add user_id column in post table for example and in the model to create

public function PostList()
    {
        return $this->belongsTo(Post::class, 'id', 'user_id')->orderBy('updated_at', 'desc');
    }

to list all post from the corrent user

and in foreach list all post

@foreach($user->PostList()->get())

@endforeach
Activity icon

Started a new Conversation View Not Found

I'm creating Recursive hasMany relationship with unlimited subcategories and on lvl 1 nested works ok category->subcategory but on lvl 2+ category->subcategory->subcategory shows

View [child_category] not found. (View: /var/www/html/resources/views/admin/categories/child_category.blade.php)

my code

model

/**
     * @return HasMany
     */
    public function categories()
    {
        return $this->hasMany(Category::class, 'parent_id');
    }

    /**
     * @return HasMany
     */
    public function children()
    {
        return $this->hasMany(Category::class, 'parent_id')->with('categories');
    }

controller

 public function index()
    {
        return Category::whereNull('parent_id')
            ->with('children')
            ->get();
    }

blade

<ul>
    @foreach ($categories as $category)
          <li>{{ $category->title }}</li>
                <ul>
                     @foreach ($category->children as $childCategory)
                         @include('admin.categories.child_category', ['child_category' => $childCategory])
                     @endforeach
                </ul>
     @endforeach
 </ul>

child_category.blade.php

<li>{{ $child_category->title }}</li>
@if ($child_category->categories)
    <ul>
        @foreach ($child_category->categories as $childCategory)
            @include('child_category', ['child_category' => $childCategory])
        @endforeach
    </ul>
@endif

on Lvl 1 is ok

View post on imgur.com
on lvl2+
View post on imgur.com
Activity icon

Replied to Error Missing Required Parameter

need to send parameter to edit method if using route model binding

return view ('Admin.Product.edit', $product);

or id passing id

return view ('Admin.Product.edit', $product->id);
Activity icon

Replied to Error Missing Requiered Parameters

show the code

Activity icon

Replied to Im New In Laravel Can Any One Please Help

public function create()
    {
        return view('admin.cars.create');
    }

do create method to go to create view where you show drop down drop down need to have for example

<select id="cars" name="cars">
    <option value="volvo">Volvo XC90</option>
    <option value="saab">Saab 95</option>
    <option value="mercedes">Mercedes SLK</option>
    <option value="audi">Audi TT</option>
  </select>

```and store method to save data in database 
public function store(Reqest $request)
{
    $car = Car::create($request->all());
    return redirect()->route('cars.edit', $car);

}
Route::resource('cars', 'CarController');

use route resources

model Car.php

class Car extends Model
{


    protected $table = 'cars';
    protected $fillable = ['cars'];


}
Apr
13
2 months ago
Activity icon

Replied to Tightenco / Ziggy

...

Activity icon

Started a new Conversation Tightenco / Ziggy

Hi I have problem with setup tightenco/ziggy

Add Ziggy to your Composer file: composer require tightenco/ziggy

(if Laravel 5.4) Add Tightenco\Ziggy\ZiggyServiceProvider::class to the providers array in your config/app.php.

Include our Blade Directive (@routes) somewhere in your template before your main application JavaScript is loaded—likely in the header somewhere.

now when open Vue js component and edit the link getting 404 or syntax error my code

methods: {
            generate() {
                axios.post(route('api.user.2fa',${this.user.eid}))
                    .then(res => {
                        this.google2fa_secret = res.data.secret;
                        this.qr_code = res.data.qr;


                    })
                    .catch(this.handleError);
            },

first trows sintax error

            disable() {
                 axios.post(`route('api.user.2fa',${this.user.eid})`, {disable: true})
                    .then(res => {
                        this.google2fa_secret = res.data.secret;
                        this.qr_code = '';
                        this.toggle = false;
                    })
                    .catch(this.handleError);
            }
        },

second trows 404 not reading the route

Apr
12
2 months ago
Activity icon

Replied to Add Language Support To An Email

it there any way to use 'lang' => $this->user->lang that is already there in the code to define translate in mail template to hard code some code for translation or to use locale to sent mail in different lang and if is possible how to do that

Apr
10
3 months ago
Activity icon

Replied to Add Language Support To An Email

before footer section doesn't matter

Activity icon

Started a new Conversation Add Language Support To An Email

I'm sending an email with a link to generate a new password and want to add a button to switch the language just to translate the static text to my email code

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Ramsey\Uuid\Uuid;

class UserProfileCreated extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * @var string
     */
    public $user;

    public function __construct($user)
    {
        $this->user = $user;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $token = app('auth.password.broker')->createToken($this->user);

        $this->withSwiftMessage(function ($message) {
            $message->getHeaders()->addTextHeader('X-Mailer-ID', Uuid::uuid4()->toString());
        });

        $this->view('user.mail.profile-created')
            ->with(['lang' => $this->user->lang, 'token' => $token])
            ->subject('Profile created on ' . config('app.name'))
            ->from(config('mail.from.address'), config('mail.from.name'));
    }
}

view

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

    <style type="text/css" rel="stylesheet" media="all">
        /* Media Queries */
        @media only screen and (max-width: 500px) {
            .button {
                width: 100% !important;
            }
        }
    </style>
</head>


<body style="margin: 0; padding: 0; width: 100%; background-color: #F2F4F6;">
<table width="100%" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%; margin: 0; padding: 0; background-color: #F2F4F6;" align="center">
            <table width="100%" cellpadding="0" cellspacing="0">
                <!-- Logo -->
                <tr>
                    <td style="padding: 25px 0; text-align: center;">
                        <a style="font-family: Arial, &#039;Helvetica Neue&#039;, Helvetica, sans-serif; font-size: 16px; font-weight: bold; color: #2F3133; text-decoration: none; text-shadow: 0 1px 0 white;"
                           href="{{ config('app.url') }}
                                   " target="_blank">
                            Tether
                        </a>
                    </td>
                </tr>

                <!-- Email Body -->
                <tr>
                    <td style="width: 100%; margin: 0; padding: 0; border-top: 1px solid #EDEFF2; border-bottom: 1px solid #EDEFF2; background-color: #FFF;"
                        width="100%">
                        <table style="width: auto; max-width: 570px; margin: 0 auto; padding: 0;" align="center"
                               width="570" cellpadding="0" cellspacing="0">
                            <tr>
                                <td style="font-family: Arial, &#039;Helvetica Neue&#039;, Helvetica, sans-serif; padding: 35px;">
                                    <!-- Greeting -->
                                    <h1 style="margin-top: 0; color: #2F3133; font-size: 19px; font-weight: bold; text-align: left;">
                                        Hello!</h1>

                                    <!-- Intro -->
                                    <p style="margin-top: 0; color: #74787E; font-size: 16px; line-height: 1.5em;">
                                        Your account on Tether has been created. Please follow the 'Create Password'
                                        link
                                        to generate a password.
                                    </p>
                                    <!-- Action Button -->
                                    <table style="width: 100%; margin: 30px auto; padding: 0; text-align: center;"
                                           align="center" width="100%" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td align="center">

                                                <a ses:no-track href="{{ url('password/reset', $token) }}"
                                                   style="font-family: Arial, &#039;Helvetica Neue&#039;, Helvetica, sans-serif; display: block; display: inline-block; width: 200px; min-height: 20px; padding: 10px; background-color: #3869D4; border-radius: 3px; color: #ffffff; font-size: 15px; line-height: 25px; text-align: center; text-decoration: none; -webkit-text-size-adjust: none; background-color: #3869D4;"
                                                   class="button"
                                                   target="_blank">
                                                    Create Password
                                                </a>
                                            </td>
                                        </tr>
                                    </table>

                                    <!-- Salutation -->
                                    <p style="margin-top: 0; color: #74787E; font-size: 16px; line-height: 1.5em;">
                                        Regards,<br>Tether
                                    </p>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <!-- Footer -->
                <tr>
                    <td>
                        <table style="width: auto; max-width: 570px; margin: 0 auto; padding: 0; text-align: center;"
                               align="center" width="570" cellpadding="0" cellspacing="0">
                            <tr>
                                <td style="font-family: Arial, &#039;Helvetica Neue&#039;, Helvetica, sans-serif; color: #AEAEAE; padding: 35px; text-align: center;">

                                    <p style="margin-top: 0; color: #74787E; font-size: 12px; line-height: 1.5em;">
                                        &copy; {{ \Carbon\Carbon::now()->year }}
                                        <a style="color: #3869D4;" href="{{ config('app.url') }}
                                                " target="_blank">Tether</a>.
                                        All rights reserved.
                                    </p>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</body>
</html>
Apr
08
3 months ago
Activity icon

Replied to Save Data To 2 Tables Connected With Pivot In 1 Method

 public function twoFA($id)
    {
        $user = User::findOrFail($id);

        $google2fa = new Google2FA();

        $user->google2fa_secret = request('disable') ? null : $google2fa->generateSecretKey();

        if (request('disable')) {
            Client::join('users_clients', 'users_clients.client_id', '=', 'clients.id')
                ->where('users_clients.user_id', '=', $user->id)
                ->update(['has_2fa' => false]);
        } else {
            Client::join('users_clients', 'users_clients.client_id', '=', 'clients.id')
                ->where('users_clients.user_id', '=', $user->id)
                ->update(['has_2fa' => true]);
        }

        $user->save();


        $clientName = Client::getMxcoClient()->name;
        $google2faQr = (new \PragmaRX\Google2FAQRCode\Google2FA());
        $qr = $google2faQr->getQRCodeInline($clientName, $user->email, $user->google2fa_secret);


        return response()->json(['secret' => $user->google2fa_secret, 'qr' => $qr]);
    }

my solution

Activity icon

Started a new Conversation Save Data To 2 Tables Connected With Pivot In 1 Method

Have 2 tables connect with pivot table, users clients and users_clients now when I enable 2FA I want to store '1' for create or '0' for disabled in has_2fa colum in clients table in same method my code

public function twoFA($id)
    {
        $user = User::findOrFail($id);

        $google2fa = new Google2FA();

        $user->google2fa_secret = request('disable') ? null : $google2fa->generateSecretKey();

   
        $user->save();


        $clientName = Client::getMxcoClient()->name;
        $google2faQr = (new \PragmaRX\Google2FAQRCode\Google2FA());
        $qr = $google2faQr->getQRCodeInline($clientName, $user->email, $user->google2fa_secret);


        return response()->json(['secret' => $user->google2fa_secret, 'qr' => $qr]);
    }

works on users but how to save in clients table in this  method
Apr
07
3 months ago
Activity icon

Started a new Conversation Error Installing Package

composer require tightenco/ziggy
Do not run Composer as root/super user! See https://getcomposer.org/root for details
                                                                                    
                                                                                                                
  [RuntimeException]                                                                                            
  Failed to execute git clone --mirror '[email protected]' '/home/ubuntu/  
  .composer/cache/vcs/git-bitbucket.org....../'                                  
                                                                                                                
  Cloning into bare repository '/home/ubuntu/.composer/cache/vcs/git-bitbucket.org-.git'...                                                                                                 
  Permission denied (publickey).                                                                                
  fatal: Could not read from remote repository.                                                                 
                                                                                                                
  Please make sure you have the correct access rights                                                           
  and the repository exists.                                                                                    
                                                                                                                

require [--dev] [--prefer-source] [--prefer-dist] [--fixed] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...
Apr
06
3 months ago
Activity icon

Replied to Show Webpage Name On My 2fa App On My Phone

My fix

$google2fa = new Google2FA();
        $environment = App::environment();
        $user->google2fa_secret = request('disable') ? null : $google2fa->generateSecretKey();
        $email = "Admin ($environment) $user->email";
        $user->save();
        $clientName = Client::getMxcoClient()->name;
        $google2faQr = (new \PragmaRX\Google2FAQRCode\Google2FA());
        $qr = $google2faQr->getQRCodeInline($clientName, $email, $user->google2fa_secret);

Activity icon

Started a new Conversation Show Webpage Name On My 2fa App On My Phone

I have enabled 2fa on my web page using this package https://github.com/antonioribeiro/google2fa when I scan the qr code it shows my email address but I need to show APP_ENV="" from .env file to have something like this

Apr
02
3 months ago
Activity icon

Started a new Conversation Pass String To Route Name

My route

Route::get(
                    'experience/{type}/create',
                    [
                        'as' => 'experience.create',
                        'uses' => '\App\Http\Controllers\[email protected]'
                    ]
                );

url : experience/pages/create (type was add manual in in the url in blade) now I want to use route name

{{route('experience.create', ['type => pages'])}}

so my question, is this good practice or not and it will work or not

Mar
26
3 months ago
Activity icon

Replied to Use Of Undefined Constant

fix it by adding single quotes acted of an apostrophe

{{ route('client-prefix.launchpad.index', [‘client’ => ClientContext::get()->eid]) }}
Mar
25
3 months ago
Activity icon

Started a new Conversation Use Of Undefined Constant

Don't understand the error and how to fix it

Tests\Feature\TicketControllerTest::testSetStatusWithMismatchedClientAndTicket ErrorException: Use of undefined constant ‘client - assumed '‘client' (this will throw an Error in a future version of PHP) (View: /var/www/tether/resources/views/errors/500.blade.php)

public function testSetStatusWithMismatchedClientAndTicket()
    {
        // Arrange
        $otherClient = factory(Client::class)->create(['name' => 'Not Visible Client']);
        $visibleClient = factory(Client::class)->create(['name' => 'Visible Client']);

        $campaign = factory(Campaign::class)->create(['client_id' => $otherClient->id]);

        $participant = factory(Participant::class)->create();
        $person = factory(ClientParticipant::class)->create([
            'client_id' => $otherClient->id,
            'participant_id' => $participant->id,
        ]);

        $ticket = factory(Ticket::class)->create([
            'client_id' => $otherClient->id,
            'campaign_id' => $campaign->id,
            'participant_client_id' => $person->id
        ]);

        $user = factory(User::class)->create();
        $user->clients()->attach($visibleClient);
        $this->actingAs($user);
        Passport::actingAs($user);

        // Act
        $response = $this->post(
            '/' . $visibleClient->eid . '/ticket/' . $ticket->fresh()->eid . '/set-status',
            ['status' => 'escalated']
        );

        // Arrange
        $response->assertStatus(403);
    }

and the blade

@extends('auth.layout')
@section('content')

    <style>
        body {
            display: block !important
        }
    </style>

    <div class="login loginBg" ng-cloak>
        <md-content class="md-padding loginBg">
            <md-card class="md-whiteframe-2dp">

                <md-card-content layout="column" layout-align="center center">

                    <h1 class="md-display-2 logo">tether</h1>
                    <h6 style="text-align:center">Internal Server Error (#500)</h6>
                    <a href="{{ route(‘client-prefix.launchpad.index’, [‘client’ => ClientContext::get()->eid]) }}">Return
                        to launchpad</a>

                </md-card-content>

            </md-card>
            <br/>
        </md-content>
    </div>

@endsection
Activity icon

Replied to Remove Extra Characters After File Extension

already try this not working

Activity icon

Started a new Conversation Remove Extra Characters After File Extension

I save an image from URL to storage using Intervention image but have a problem when the image come in this format

104202.jpg?w=318&#038;h=480

hot to stip everything after image extension

Mar
24
3 months ago
Activity icon

Replied to Test Invitation Mail

txh man

Activity icon

Replied to Test Invitation Mail

  1. Tests\User\Controllers\UserControllerTest::testStoreWithInvitationMail Illuminate\Session\TokenMismatchException:
Activity icon

Replied to Test Invitation Mail

this is the error mail is not sending don't understand why

  1. Tests\User\Controllers\UserControllerTest::testStoreWithInvitationMail The expected [App\Mail\UserProfileCreated] mailable was sent 0 times instead of 1 times. Failed asserting that false is true.
Activity icon

Replied to Test Invitation Mail

code refactored to

public static function sendWelcomeEmail($user)
    {
        $token = app('auth.password.broker')->createToken($user);
        Mail::to($user->email)->send(new UserProfileCreated($user->language, $user->mailerId, $token));
    } 

but test still not working

Activity icon

Started a new Conversation Test Invitation Mail

When admin create a user it sends invitation email with a password reset link and it working nice when is sending the mail manually on the staging server but need to write a test but when run the test is failing hire is my code

Controller

public function store(CreateUser $request)
    {
        $input = $request->validated();
        if ($user = User::getByEmail($input['email'], true)) {
            $user->deleted_at = null;
        } else {
            $user = new User;
        }

        $client = ClientContext::get();

        $user->email = $input['email'];
        $user->name = $input['name'];
        $user->phone = $client->shortcodes()->first()->phoneFormatter()->format($input['phone']);
        $user->language = $input['language'];

        $client_id = $input['client_id'];

        $user->password = Hash::make(Str::random(64));

        $now = gmdate('Y-m-d H:i:s');
        $user->updated_at = $now;

        $user->save();

        $user->clients()->sync(
            [
                $client_id => [
                    'client_role_id' => $input['client_role_id'],
                    'timezone' => $input['timezone'],
                ],
            ],
            false
        );

        if (!empty($input['lists'])) {
            $lists = explode(',', $input['lists']);
            $user->lists()->sync($lists);
        }
        Cache::tags(['clients'])->forget("user.{$user->eid}.clients");

        if (isset($input['invite'])) {
            $email = app(Email::class);
            $email->subject = 'Profile created on ' . config('app.name');
            $mailerId = Uuid::uuid4()->toString();
            $email->mailer_id = $mailerId;
            $email->user_id = $user->id;
            $email->save();
            User::sendWelcomeEmail($user);
        }

        return redirect('/user');
    }

Model

public static function sendWelcomeEmail($user)
    {
        $token = app('auth.password.broker')->createToken($user);
        Mail::send('user.mail.profile-created', compact('token', 'user'), function ($m) use ($user) {
            $m->from(
                '[email protected]' . parse_url(config('app.url'), PHP_URL_HOST)
            );
            $m->to($user->email)->subject('Welcome to Tether');
            $headers = $m->getHeaders();
            $headers->addTextHeader('X-Mailer-ID', $user->mailerId);
        });
    }

Test

public function testStoreWithInvitationMail()
    {
        Mail::fake();

        $client = factory(Client::class)->create(['has_dedicated_shortcode' => true]);
        $shortcode = factory(Shortcode::class)->create();
        $client->shortcodes()->attach($shortcode);
        $person = factory(ClientParticipant::class)->states('email')->create([
                'client_id' => $client->id,
            ]);
        $user = $this->createAdministrator($client);
        Passport::actingAs($user);
        $clientRole = factory(ClientRole::class)->states(['mxco'])->create();

        $params = [
            'email' => $this->faker->email,
            'name' => $this->faker->name,
            'phone' => $this->faker->phoneNumber,
            'client_id' => $client->id,
            'client_role_id' => $clientRole->id,
            'language' => 'en',
            'timezone' => 'US/Eastern',
            'keyword' => null,
            'territory_number' => null,
            'invite' => true
        ];

        $response = $this
            ->actingAs($user)
            ->sessionClient($client)
            ->post('/user', $params);

        $this->assertEquals(302, $response->getStatusCode());

        Mail::assertSent(UserProfileCreated::class, 1);
    }

and the UserProfileCreated class

class UserProfileCreated extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * @var string
     */
    public $lang;

    /**
     * @var string
     */
    private $mailerId;

    public function __construct($lang, $mailerId)
    {
        $this->lang = $lang;
        $this->mailerId = $mailerId;
    }

    /**
     * Build the message.
     *
     * @return void
     */
    public function build()
    {
        $this->withSwiftMessage(function ($message) {
            $message->getHeaders()->addTextHeader('X-Mailer-ID', $this->mailerId);
        });

        $this->view('user.mail.profile-created')
            ->with(['$lang' => $this->lang])
            ->subject('Profile created on ' . config('app.name'))
            ->from(config('mail.from.address'), config('mail.from.name'));
    }
}
Mar
19
3 months ago
Activity icon

Started a new Conversation Class 'Illuminate\Support\Facades\Input' Not Found

After update to laravel 6 Class 'Illuminate\Support\Facades\Input' not found an error shows and in the controller I have a try

use Illuminate\Support\Facades\Input; use Input; but is the same

I bypass it adding

        'Input' => Illuminate\Support\Facades\Request::class,

in config app

Mar
17
3 months ago
Activity icon

Replied to Reload Page In Vue.js

thx man for the help and telling me the write way

Activity icon

Replied to Reload Page In Vue.js

this was the solution

                        this.$forceUpdate();  // Calling forceUpdate will only force the view to re-render.
Activity icon

Replied to Reload Page In Vue.js

Still noting show on generate how I see you have made a change on disable or I em wrong

Activity icon

Replied to Reload Page In Vue.js

can you show me what I need to do is my second day with vue.js and need to debag this

Activity icon

Started a new Conversation Reload Page In Vue.js

This is my component and when I click on generate button key is generating but is not showing until I press refresh how to fix it or to reload the page on click

<template>
    <div class="text-center">
        <div class="checkbox">
            <label>
                <input type="checkbox" v-model="toggle" :disabled="user.google2fa_secret"> {{ toggletext }}
            </label>
        </div>

        <hr>
        <div v-if="toggle">
            <div v-if="user.google2fa_secret">
                <p v-if="user.google2fa_secret">Your 2FA Secret Key</p>
                <h3>{{ user.google2fa_secret }}</h3>

                <button class="md-button md-raised md-accent" @click="disable">{{ disabletext }}</button>

                <p>Instructions for first time setup:</p>
                <p>Please install the <a :href="google_link">Google Authenticator</a> first.</p>
                <p>
                    You can install it from the
                    <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en">Google
                        Play</a> or
                    <a href="https://apps.apple.com/us/app/google-authenticator/id388497605">Apple Store</a>.
                </p>

                <p>Scan The QR code:</p>
                <img :src="qr_code" alt="qr_code"/>
                <br>

                <form action="/google2fa/authenticate" method="POST">
                    <input type="hidden" v-model="csrf" name="_token">
                    <input name="one_time_password" type="text">

                    <button type="submit">Authenticate</button>
                </form>


            </div>

            <div v-else>
                <button class="md-button md-raised md-accent" @click="generate">{{ generatetext }}</button>
            </div>
        </div>

        <div v-else>
            <p>You don't have the 2FA enabled.</p>
        </div>


    </div>

</template>

<script>
    import axios from 'axios';

    export default {
        name: "TwoFactorAuth",
        props: {
            qr: {
                type: String,
                required: false,
                default: '',
            },
            user: {
                type: Object,
                required: true,
            },
            toggletext: {
                type: String,
                required: true,
            },
            generatetext: {
                type: String,
                required: true,
            },
            disabletext: {
                type: String,
                required: true,
            },
        },
        data() {
            return {
                toggle: !!this.user.google2fa_secret,
                google_link: 'https://www.google.com/landing/2step/',
                qr_code: this.qr,
                csrf: ''
            }
        },
        methods: {
            generate() {
                axios.post(`/api/user/${this.user.eid}/2fa`)
                    .then(res => {
                        this.user.google2fa_secret = res.data.secret;
                        this.secret = this.user.google2fa_secret;
                        this.qr_code = res.data.qr;


                    })
                    .catch(this.handleError);
            },
            disable() {
                axios.post(`/api/user/${this.user.eid}/2fa`, {disable: true})
                    .then(res => {
                        this.user.google2fa_secret = res.data.secret;
                        this.qr_code = '';
                        this.toggle = false;
                    })
                    .catch(this.handleError);
            }
        },
        mounted() {
            this.csrf = document.head.querySelector('meta[name="csrf-token"]').content;

        }
    }
</script>

<style scoped>

</style>
Mar
16
3 months ago
Activity icon

Started a new Conversation Unit Test 2FA

have implemented Google 2 factor Authorization on my page and it is working but I was wondering if it possible to unit test it, if can be done, can someone tell me how to do it

Mar
12
3 months ago
Activity icon

Started a new Conversation Google2FA-Laravel Validation

I em using Google2FA-Laravel package and everything is ok but not find an example how to validate the numbers that are coming from my phone returns