English 中文(简体)
Laravel - 用户简介
原标题:Laravel - User profile pages
  • 时间:2019-09-22 22:52:30
  •  标签:
  • laravel

In my app I have a users table and a profiles table. When a user goes to their dashboard, they should be able to click a link to view their profile page. Here s the link:

<a href=”{路边(简介,show ,$profiles->id>>link to You Profile page</a>

然而,我正在发现错误:Route [profiles.show]没有界定。

I m a novice and is not clear on how tolink a signed upuser with his/her Profile page. 所有用户都应有一个插图页。

我赞赏一些指导! 这就是我迄今为止所做的事情:


www.un.org/Depts/DGACM/index_spanish.htm 链接

<a href=”{路边(简介,show ,$profiles->id>>link to You Profile page</a>

<>ProfilesController.php


namespace AppHttpControllers;

use AppProfile;
use IlluminateHttpRequest;

class ProfilesController extends Controller
{
    public function show($id)
    {
        $profile = Profile::find($id);
        return view( profiles.show , compact( profile ));
    }
}

www.un.org/Depts/DGACM/index_spanish.htm Profile.php


namespace App;

use IlluminateDatabaseEloquentModel;

class Profile extends Model
{
    public function user()
    {
        return $this->belongsTo( User );
    }
}

routes/web.php

Route:get( pages/profiles , ProfilesController@show );

profiles.blade.php

www.un.org/Depts/DGACM/index_spanish.htm 现在,这只是一个非常简单的网页。

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <h1>{{ $user->user_id }}</h1>

    <p>{{ $user->about_me }}</p>
</body>

</html>

<>Solution

I found an easy solution and I wanted to post it here to help others who might be struggling with creating a user profile page. The below assumes you already have a users table in your database and now you want to create a profiles table and connect user ID to their profile page. Adding Laravel User Profiles

http://www.you Programme.com/watch?v=yAVvOW64c0g”rel=“nofollow noreferer” 帮助我的视频

<><>>>

php artisan make:migration create_profiles_table 

This creates a migration file:

2019_09_22_213316_create_profiles_table

www.un.org/Depts/DGACM/index_spanish.htm 开放式移民档案和增加以下几栏:

$table->integer( user_id )->unsigned()->nullable();
$table->string( about_me )->nullable();

www.un.org/Depts/DGACM/index_spanish.htm 将这些数据输入数据库

php artisan migrate

www.un.org/Depts/DGACM/index_spanish.htm 现在,我们的数据库已经分类,我们需要建立一个控制器,控制我们的实验室如何运作。

ProfilesController.php
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class ProfilesController extends Controller
{
    public function show($user_id)
    {
        $user = User::find(1);
        $user_profile = Profile::info($user_id)->first();
        return view( profiles.show , compact( profile ,  user ));
    }

    public function profile()
    {
        return $this->hasOne( Profile );
    }
}

routes/web.php

Route::get( dashboard/profile ,  ProfilesController@show );

www.un.org/Depts/DGACM/index_spanish.htm Profile.php

<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class Profile extends Model
{
    public function user()
    {
        return $this->belongsTo( User );
    }
}

Add this to User.php

public function profile()
{
return $this->hasOne( Profile );
}

.blade.php

创造你们想要的任何设计。 如果你想用用户名称,包括<代码>{> Auth:user()->name

问题回答

审判

Route::get( pages/profiles/{id} ,  ProfilesController@show )->name( profiles.show );

由于你使用一个名字路线,但上网。 php没有名称路线,称为简介。 显示:

*>,显示错误。 And In Line You Need 发放身份证。

At Blade file:

<a href="{{ route( profiles.show ,$profiles->id)}}">link to your profile page</a>

改变路线 如下:

Route::get( pages/profiles/{id} ,  ProfilesController@show )->name( profiles.show );

简介

public function user()
{
    return $this->belongsTo(User::class);
}

In Profiles.blade.php

<body>
  <h1>{{ $profile->id }}</h1>

   <p>{{ $profile->about_me }}</p>
</body>

You Passed 用户信息通过“引人注目”参数。 因此,你必须用刀子书写这一名字。

Note Route Function won t work if you don t mentioned any name for this Route name. Either you have to use URL.

你的路线错了,请看Route: (, 您必须人工标明您的路线,并具体说明您在预计参数时(此处为情况简介)。

Route::get( pages/profiles/{id} ,  ProfilesController@show )->name( profiles.show );
<a href="{{ route( profiles.show , $profile)}}">link to your profile page</a>

Route model binding is probably the way to go in this case.

Route::get( pages/profiles/{profile} ,  ProfilesController@show )->name( profiles.show );
namespace AppHttpControllers;

use AppProfile;
use IlluminateHttpRequest;

class ProfilesController extends Controller
{
    public function show(Profile $profile)
    {
        return view( profiles.show , compact( profile ));
    }
}




相关问题
Table of calificacions in php and laravel

I created a table in order to show the name of the students, name of the subjects and the grade of the subject of the student I have the next code: this is the index part <form action="{{ ...

How to fix CORS for Capacitor/Quasar App in a Laravel API

I have an App built on top of Quasar and Capacitor, with an API built on top of Laravel. Everything works well on the dev environment until I build and install the app on my phone, then I keep getting ...

Laravel +Vuejs CORS issue

I am facing a dilemma wit the CORS issue. I have application that is configured as follow: API: https://abc.mydomain.com (laravel) front end: https://subdomain.mydomain.com(VueJS) Both applications ...

Laravel wrong redirecting to login page after login

In a multi tenancy with subdomain enviroment (http://zapburger.dex.local) when user fills login form with valid data and make login, laravel redirect to dashboard route (as expected) and then redirect ...

热门标签