MrAli

MrAli

Member Since 3 Years Ago

Experience Points
1,960
Total
Experience

3,040 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
17
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
1,960 XP
May
19
2 weeks ago
Activity icon

Replied to Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

Msgs

Schema::create('msgs', function (Blueprint $table) {
            $table->id();
            $table->string('link')->nullable();
            $table->string('body');
            $table->foreignId('user_id')->constrained()->nullable();
            $table->foreignId('msg_id')->constrained()->nullable(); // For replays 
            $table->string('ip')->nullable();
            $table->boolean('is_active')->nullable();
            $table->softDeletes();
            $table->timestamps();

Users

$table->id();
            $table->string('name');
            $table->string('username')->unique();
            $table->string('avatar')->nullable();
            $table->string('email')->unique();
            $table->string('bio')->nullable();
            $table->string('url')->nullable();
            $table->string('city')->nullable();
            $table->string('country')->nullable();
            $table->string('ip')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->string('provider')->nullable(); // https://artisansweb.net/login-with-twitter-in-laravel-using-laravel-socialite/
            $table->string('provider_id')->nullable();
            $table->boolean('is_active')->default('1');
            $table->rememberToken();
            $table->softDeletes();
            $table->timestamps();
Activity icon

Replied to Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

I just can't finger this out . I did a lot of googling and laravel Docs reading.

User.php

<?php

namespace App;

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

class User extends \TCG\Voyager\Models\User
{
    use Notifiable;

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

    /**
     * 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 msgs()
    {
        return $this->hasMany('App\Msg')->latest();
    }

    public function getRouteKeyName()
        {
            return 'username';
        }
}

Msg.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Msg extends Model
{
    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function getRouteKeyName()
        {
            return 'link';
        }
}

web.php

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', '[email protected]');

Auth::routes();
// Route::resource('{user:username:user:usernamename}/{img:link}', 'MsgsController');

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


Route::group(['prefix' => 'admin'], function () {
    Voyager::routes();
});


Route::Get('/{user:username}', '[email protected]');
Route::Get('/{user:username}/create', '[email protected]')->name('create'); // {user:username}/add
Route::Post('/{user:username}/{msg:link}', '[email protected]')->name('store');
Route::GET('/{user:username}/{msg:link}', '[email protected]')->name('show');
Route::GET('/{user:username}/{msg:link}/edit', '[email protected]')->name('edit');
Route::PUT('/{user:username}/{msg:link}', '[email protected]')->name('update');
Route::DELETE('/{user:username}/{msg:link}', '[email protected]')->name('destroy');

MsgsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; 
// use Illuminate\Support\Facades\DB;
use App\Msg;
use App\User;

class MsgsController extends Controller
{
    public function __construct()
        {
            $this->middleware('auth', ['except' => ['index', 'show']]);
        }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index($id)
    {
        // $msgs = Msg::orderBy('created_at', 'desc')->get();
        // $msg = Msg::orderBy('created_at', 'desc')->get();
        // return view('msgs')->with('msg', $msg);
        $msg = Msg::find($id);
        $user_id = Auth::id();
        $user = User::find($user_id);
        return view('msgs')
        ->with('msg', $msg)
        ->with('user', $user);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $user_id = Auth::id();
        $user = User::find($user_id);
        return view('createmsg')->with('user', $user);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'body'  => 'required',            
        ]);

        // Create Msg
        $msg              =  new Msg;
        $msg->user_id     =  auth()->user()->id;
        $msg->link        =  bin2hex(random_bytes(3)).time(); 
        $msg->body        =  $request->input('body');
        $msg->ip          =  $request->ip();
        $msg->msg_id      =  null;
        $msg->is_active   =  1;

        $msg->save();

        return redirect('/profile')->with('success', 'Send'); //   /{username}/{link}
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($msg)
    {
        $msg = Msg::find($msg);
        $user_id = Auth::id();
        $user = User::find($user_id);
        return view('showmsg')
        ->with('msg', $msg)
        ->with('user', $user);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $msg = Msg::find($id);
        $user_id = Auth::id();
        $user = User::find($user_id);
        return view('editmsg')
        ->with('msg', $msg)
        ->with('user', $user);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'body'  => 'required',            
        ]);

        // Create Msg
        $msg              =  Msg::find($id);
        $msg->user_id     =  auth()->user()->id;
        $msg->link        =  bin2hex(random_bytes(3)).time();
        $msg->body        =  $request->input('body');
        $msg->ip          =  $request->ip();
        $msg->msg_id      =  null;
        $msg->is_active   =  1;

        $msg->save();

        return redirect('/profile')->with('success', 'Send'); //   /{username}/{link}
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $msg = Msg::find($id);
        $msg->delete();

        return redirect('/profile')->with('success', 'Send');
    }
}

ProfileController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; // i added from https://laravel.com/docs/7.x/authentication#retrieving-the-authenticated-user
use App\User;

class ProfileController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $user_id = Auth::id();
        $user_id = Auth::id();

        $user = User::find($user_id);

        return view('profile')->with('msgs', $user->msgs);
    }
}

createmsg.blade.php

@extends('layouts.app')

@section('content')
  <div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <h1>Create.blade.php</h1>
            <div class="card">
                <div class="card-header">Write Msg</div>

                <div class="card-body">
                    @if (session('status'))
                        <div class="alert alert-success" role="alert">
                            {{ session('status') }}
                        </div>
                    @endif

                    {{-- You are logged in! --}}
                    {!!Form::open(['action' => ['[email protected]' , $user->username], 'method' => 'POST', 'enctype' => 'multipart/form-data'])!!}
                      {{Form::bsTextArea('body', '', ['placeholder' => 'msg text'])}}

                      <input type="submit" value="Senddd" class="btn btn-primary btn-lg" id="send">
                    {!!Form::close()!!}
                </div>
            </div>
        </div>
    </div>
</div>    
@endsection

editmsg.blade.php

@extends('layouts.app')

@section('content')
  <div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <h1>editmsg.blade.php</h1>
            <div class="card">
                <div class="card-header">Edit Msg</div>

                <div class="card-body">
                    @if (session('status'))
                        <div class="alert alert-success" role="alert">
                            {{ session('status') }}
                        </div>
                    @endif

                    {{-- You are logged in! --}}
                    {!!Form::open(['action' => ['[email protected]' , $msg->id], 'method' => 'POST', 'enctype' => 'multipart/form-data'])!!}
                      {{Form::bsTextArea('body', $msg->body , ['placeholder' => 'Msgs Text'])}}
                      {{Form::hidden('_method', 'PUT')}}

                      <input type="submit" value="Sendd" class="btn btn-primary btn-lg" id="send">
                  {!!Form::close()!!}
                </div>
            </div>
        </div>
    </div>
</div>    
@endsection

msgs.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <h1>msgs.blade.php</h1>
            <div class="card">
                <div class="card-header">msgs</div>
                {{-- {{dd($msg)}} --}}
                <div class="card-body">
                    @if (session('status'))
                        <div class="alert alert-success" role="alert">
                            {{ session('status') }}
                        </div>
                    @endif

                    {{-- You are logged in! --}}
                    @if (count($msgs))
                      <ul class="list-groug">
                            @foreach ($msgs as $msg)
                      {{-- <li class="list-group-item"><a href="{{route('show', $msg->link)}}">{{$msg->body}}</a></li>                                  --}}
                      <a href="{{ route('show', $msg->id) }}">{{$msg->body}}</a>
                            @endforeach
                      </ul>
                    @else
                      <p>There is no Msg</p>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

profile.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <h1>Profile.blade.php</h1>
            <div class="card">
                <div class="card-header">Dashboard</div>

                <div class="card-body">
                    @if (session('status'))
                        <div class="alert alert-success" role="alert">
                            {{ session('status') }}
                        </div>
                    @endif

                    {{-- You are logged in! --}}
                    <h3>your Msgs</h3>
                    @if (count($msgs))
                        <table class="table table-striped">
                            <tr>
                                <th>Msg</th>
                                <th></th>
                                <th></th>
                            </tr>
                            @foreach ($msgs as $msg)
                                <tr>
                                    <td>{{$msg->body}}</td>
                                    <td><a class="btn btn-primary" href="/d/{{$msg->id}}/edit">Edit</a></td>
                                    <td>
                                        {!!Form::open(['action' => ['[email protected]' , $msg->id], 'method' => 'POST', 'enctype' => 'multipart/form-data', 'onsubmit' => 'return confirm("Are yOU sURE??")'])!!}

                                            {{Form::hidden('_method', 'DELETE')}}
                                            <input type="submit" value="Deleteee" class="btn btn-danger btn-lg" id="send">
                                        {!!Form::close()!!}
                                    </td>
                                </tr>
                            @endforeach
                        </table>                        
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

showmsg.blade.php

@extends('layouts.app')

@section('content')
  <div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <h1>Showmsg.blade.php</h1>
            <div class="card">
                <div class="card-header">MSG</div>

                <div class="card-body">
                    @if (session('status'))
                        <div class="alert alert-success" role="alert">
                            {{ session('status') }}
                        </div>
                    @endif

                    {{-- You are logged in! --}}
                    <div class="well">
                      {{$msg->body}}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>    
@endsection
Activity icon

Replied to Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

Let's Back to square one.

web.php

oute::resource('{user:username}/{img:link}', 'MsgsController');

λ php artisan route:list

Green Box: What i need. Red Box: What laraval give me. Yellow Box: \resources\views*.blade.php

users in db

msgs in db

May
18
2 weeks ago
Activity icon

Replied to Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

Post::findOrFail($id) Don't show error details so i use Post::find($id).

Activity icon

Replied to Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

@michaloravec

I did read what you wrote.

 Missing required parameters for [Route: ] [URI: {user}/{post}]. (View: C:\xampp\htdocs\d\resources\views\editpost.blade.php)
http://127.0.0.1:8000/MrAli/5478/edit 
Route::Get('/{user:username}', '[email protected]');
Route::Get('/{user:username}/create', '[email protected]'); // {user:username}/add
Route::Post('/{user:username}/{post:link}', '[email protected]');
Route::GET('/{user:username}/{post:link}', '[email protected]');
Route::GET('/{user:username}/{post:link}/edit', '[email protected]');
Route::PUT('/{user:username}/{post:link}', '[email protected]');
Route::DELETE('/{user:username}/{post:link}', '[email protected]');

public function edit($post_link, $user_username) 
    {
        $post = Post::find($post_link);
        $user_id = Auth::id();
        $user = User::find($user_username);
        return view('editpost')
        ->with('post', $post)
        ->with('user', $user);
    }

I comment out getRouteKeyName() in User.php and Post.php

Activity icon

Replied to Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

@michaloravec @m7vm7v @drewdan

I still getting this error

 Trying to get property 'slug' of non-object (View: C:\xampp\htdocs\d\resources\views\editpost.blade.php)
http://127.0.0.1:8000/MrAli/5478/edit 

And this error

 Trying to get property 'body' of non-object (View: C:\xampp\htdocs\d\resources\views\showpost.blade.php)
http://127.0.0.1:8000/MrAli/5478 

web.php

<?php

use Illuminate\Support\Facades\Route;

Auth::routes();

Route::Get('/{user}', '[email protected]');
Route::Get('/{user}/create', '[email protected]'); 
Route::Post('/{user}/{post}', '[email protected]');
Route::GET('/{user}/{post}', '[email protected]');
Route::GET('/{user}/{post}/edit', '[email protected]');
Route::PUT('/{user}/{post}', '[email protected]');
Route::DELETE('/{user}/{post}', '[email protected]');


Route::group(['prefix' => 'admin'], function () {
    Voyager::routes();
});


User.php

<?php

namespace App;

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

class User extends \TCG\Voyager\Models\User
{
    use Notifiable;

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

    /**
     * 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 posts()
    {
        return $this->hasMany('App\Post')->latest();
    }

    public function getRouteKeyName() __//Thanks To @m7vm7v__
        {
            return 'username';
        }
}

public function getRouteKeyName() //Thanks To @m7vm7v

Post.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function getRouteKeyName()
        {
            return 'slug';
        }
}

PostController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; 
// use Illuminate\Support\Facades\DB;
use App\post;
use App\User;

class PostsController extends Controller
{
    public function __construct()
        {
            $this->middleware('auth', ['except' => ['index', 'show']]);
        }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // $user_id = Auth::id();
        // $user = User::find($user_id);
        // $posts = $user->posts()->get(); 
        // return view('posts')->with('posts', $posts);

         // https://github.com/laracasts/Tweety/blob/master/app/Http/Controllers/HomeController.php
           return view('posts', [
            'posts' => auth()->user()
            // 'tweets' => auth()->user()->timeline()
        ]);
    
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $user_id = Auth::id();
        $user = User::find($user_id);
        return view('createpost')->with('user', $user);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'body'  => 'required',            
        ]);

        // Create post
        $post              =  new Post;
        $post->user_id     =  auth()->user()->id;
        $post->link        =  bin2hex(random_bytes(3)).time(); 
        $post->body        =  $request->input('body');
        $post->ip          =  $request->ip();
        $post->post_id      =  null;
        $post->is_active   =  1;

        $post->save();

        return redirect('/profile')->with('success', 'Send!'); //   /{username}/{link}
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    // public function show($id)
    // public function show(User $user, Post $post)
    public function show($id)
    {
        $post = Post::find($id);
        return view('showpost')->with('post', $post);        
        
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $post = Post::find($id);
        $user_id = Auth::id();
        $user = User::find($user_id);
        return view('editpost')
        ->with('post', $post)
        ->with('user', $user);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'body'  => 'required',            
        ]);

        // Create Post
        $post              =  Post::find($id);
        $post->user_id     =  auth()->user()->id;
        $post->link        =  bin2hex(random_bytes(3)).time(); 
        $post->body        =  $request->input('body');
        $post->ip          =  $request->ip();
        $post->post_id      =  null;
        $post->is_active   =  1;

        $post->save();

        return redirect('/profile')->with('success', 'Send!'); //   /{username}/{link}
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $post = Post::find($id);
        $post->delete();

        return redirect('/profile')->with('success', 'Send! ');
    }
}

Activity icon

Replied to Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

@michaloravec Thank you for your replay.

Yes, It should be CRUD.

Is there away so i can edit Route::resources ?

Activity icon

Replied to Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

@m7vm7v Thank you for your replay. I am sill looking for solution.

web.php

Route::resource('{user}', 'PostsController');
λ php artisan route:list 


GET|HEAD  | {user}               | {user}.index   | App\Http\Controllers\[email protected]
POST      | {user}               | {user}.store   | App\Http\Controllers\[email protected]
GET|HEAD  | {user}/create        | {user}.create  | App\Http\Controllers\[email protected]
DELETE    | {user}/{{user}}      | {user}.destroy | App\Http\Controllers\[email protected]
GET|HEAD  | {user}/{{user}}      | {user}.show    | App\Http\Controllers\[email protected]
UT|PATCH | {user}/{{user}}      | {user}.update  | App\Http\Controllers\[email protected]
GET|HEAD  | {user}/{{user}}/edit | {user}.edit    | App\Http\Controllers\[email protected]

index store create Work Fine destroy show update edit show the username twice

site.com/M7VM7V/M7VM7V/slug wrong

site.com/M7VM7V/slug correct

And i sow the video and tried getRouteKeyName() in the Model.

I think the problem is from Route::resource.

May
17
2 weeks ago
Activity icon

Started a new Conversation Route Pattern "/{username}/{{username}}" Cannot Reference Variable Name "username" More Than Once.

Hi

I am building web app. where url need to be like:

site.com/{username}/{id}

Route::get('/', '[email protected]');

Auth::routes();
Route::resource('post', 'PsotsController');

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

so i did

Route::resource('{username}', 'PostsController');

and i get the error : Route pattern "/{username}/{{username}}" .

λ php artisan route:list
.

 {username}                   | {username}.index   | App\Http\Controllers\[email protected]
 {username}                   | {username}.store   | App\Http\Controllers\[email protected]
 {username}/create            | {username}.create  | App\Http\Controllers\[email protected]
 {username}/{{username}}      | {username}.update  | App\Http\Controllers\[email protected]
 {username}/{{username}}      | {username}.show    | App\Http\Controllers\[email protected]
 {username}/{{username}}      | {username}.destroy | App\Http\Controllers\[email protected]
 {username}/{{username}}/edit | {username}.edit    | App\Http\Controllers\[email protected]

How to delete the second {{username}} from the url pattern?

May
04
4 weeks ago
Activity icon

Started a new Conversation <img> Arabic Name

Hi,

Laravel render Arabic filename in weird why.


 <img src=" {{  صورة.jpg )  }} "  />


// Laravel render this :)

صورة.jpg

// To this :(


%D8%B5%D9%88%D8%B1%D8%A9.jpg

Then I get 404 not found error. And broken img tag.

Any idea?

May
02
1 month ago
Activity icon

Replied to Undefined Variable: Gov

Thank you :D

Activity icon

Replied to Undefined Variable: Gov

Now I am getting Undefined variable: orgs.

So i did comment out $org. And $gov did WORK FINE in the view MANY THANKS.

How can make them both show in the view ?

public function index()
    {
        $orgs = Org::orderBy('created_at', 'desc')->get();
        // $orgs = Org::with('gov')->get();
        // dd($orgs);
        $gov = Gov::find(1);
        return view('orgs')->with(['orgs', $orgs, 'gov' => $gov]);
Activity icon

Started a new Conversation Undefined Variable: Gov

Hi,

I am building listing for organizations. Every things work fine ( user can CRUD org ).

Now I need to add a new relationship call gov. So I can do this.

Org Name:     {{$org->name}}
Authorized by: {{$gov->name}}   // This line rise an error Undefined variable: gov

Org.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Org extends Model
{
    public function user(){
            return $this->belongsTo('App\User');
        }
    
    public function gov(){
            return $this->belongsTo('App\Gov');    //  Can Model belongs to two other? 
        }
}
 

Gov.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class Gov extends Model
{
    // Add One to Many Relationship
    public function orgs(){
            return $this->hasMany('App\Org');
        }
}

OrgsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Org;                                       
use App\Gov;                                      

class OrgsController extends Controller
{

    public function __construct(){
            $this->middleware('auth', ['except' => ['index', 'show']]);
        }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $orgs = Org::orderBy('created_at', 'desc')->get();
        // $orgs = Org::with('gov')->get();
        // dd($orgs);
        $gov = Gov::find(1);
        return view('orgs')->with('orgs', $orgs);
    }

Any idea?