Tag: laravel

Laravel迁移:即使指定,唯一的关键是太长

我正在尝试在Laravel中迁移用户表。 当我运行我的迁移时,我得到这个错误: [Illuminate \ Database \ QueryException] SQLSTATE [42000]:语法错误或访问冲突:1071指定的键过长; 最大密钥长度是767字节(SQL:alter table users添加唯一的users_email_uniq( email )) 我的移民如下: Schema::create('users', function(Blueprint $table) { $table->increments('id'); $table->string('name', 32); $table->string('username', 32); $table->string('email', 320); $table->string('password', 64); $table->string('role', 32); $table->string('confirmation_code'); $table->boolean('confirmed')->default(true); $table->timestamps(); $table->unique('email', 'users_email_uniq'); }); 一些谷歌search后,我遇到了这个错误报告 ,泰勒说,你可以指定索引键作为unique() ,我已经完成的第二个参数。 它仍然给出了错误。 这里发生了什么?

如何使用Eloquent删除表中的所有行?

我的猜测是使用以下语法: MyModel::all()->delete(); 但是这没有用。 我相信这是非常简单的,但我已经search了关于这个主题的文档,找不到它!

Laravel – 路线::资源vs路线::控制器

我阅读了Laravel网站上的文档,Stack Overflow和Google,但仍不明白Route::resource和Route::controller之间的区别。 其中一个回答说路线::资源是crud。 但是,通过Route :: controller,我们可以完成与Route :: resource相同的事情,我们只能指定所需的操作。 他们看起来像兄弟姐妹: Route::controller('post','PostController'); Route::resource('post','PostController'); 我们如何select使用什么? 什么是好的做法?

laravel 5:未find类“input”

在我的routes.php文件中我有: Route::get('/', function () { return view('login'); }); Route::get('/index', function(){ return view('index'); }); Route::get('/register', function(){ return view('register'); }); Route::post('/register',function(){ $user = new \App\User; $user->username = input::get('username'); $user->email = input::get('email'); $user->password = Hash::make(input::get('username')); $user->designation = input::get('designation'); $user->save(); }); 我有一个用户registry单。 我也采取了routes.php的表单input值。 但是,当我注册用户时出现错误。 错误: FatalErrorException in routes.php line 61: Class 'input' not found

PHP Composer更新“无法分配内存”错误(使用Laravel 4)

我无法解决这个问题。 我在Linode 1G RAM基本计划。 试图通过composer php安装一个包,它不让我。 我的内存限制在PHP.ini上设置为“-1” 还有什么我可以做到这一点安装? Loading composer repositories with package information Updating dependencies (including require-dev) – Installing thujohn/rss (dev-master df80a7d) Downloading: 100% PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed – Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:975 Stack trace: #0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo…', 'phar:///usr/loc…', 975, Array) #1 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(975): […]

如何安装Laravel 5.0

我无法使Laravel 5.0的testing实例正常运行,所以我可以协助完成这个过渡。 1)从https://github.com/laravel/laravel/tree/develop创build一个新的应用程序导致运行composer install时出现以下错误。 {"error": {"type":"ErrorException", "message":"Undefined index: timezone", "file":"\/Projects\/indatus\/dispatcher-test-app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/start.php", "line":167} } {"error": {"type":"ErrorException", "message":"Undefined index: timezone", "file":"\/Projects\/indatus\/dispatcher-test-app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/start.php", "line":167}} 我完全错过了什么? 更新:这个问题只有在Laravel 5处于开发阶段才有意义。 现在您应该参考Laravel文档来了解如何安装Laravel

Laravel 4:如何运行一个原始的SQL?

我想在Laravel 4中重新命名一个表格,但是不知道怎么做。 SQL将alter table photos rename to images 。 如果有一个雄辩的解决scheme,我也想知道如何运行一个原始的SQL,因为有时候没有别的select。

在Laravel Eloquent中使用“with()”函数获取特定的列

我有两个表User和Post One User有很多posts ,一个post只属于一个user 。 在我的User模型中,我有许多关系 public function post(){ return $this->hasmany('post'); } 而在我的post模式,我有belongsTo像关系 public function user(){ return $this->belongsTo('user'); } 现在我想要使用Eloquent with()join这两个表Eloquent with()但希望第二个表中的特定列。 我知道我可以使用query Builder但我不会使用它。 当我在post模式写我 public function getAllPosts() { return Post::with('user')->get(); } 它运行以下queires select * from `posts` select * from `users` where `users`.`id` in (<1>, <2>) 但我想要 select * from `posts` select id,username from `users` […]

如何在Laravel雄辩查询(或使用查询生成器)中对表进行别名?

假设我们正在使用Laravel的查询构build器: $users = DB::table('really_long_table_name') ->select('really_long_table_name.id') ->get(); 我正在寻找一个相当于这个SQL: really_long_table_name AS short_name 当我必须键入大量的select和wherts时(或者通常我在select的列别名中包含别名,并且它在结果数组中使用),这将特别有用。 没有任何表别名,有更多的打字对我来说,一切都变得不太可读。 在laravel文档找不到答案,有什么想法?

Laravel 5 – 如何访问视图中的存储上传的图像?

我有用户的头像上传到Laravel存储。 我怎样才能访问它们并在视图中渲染它们? 服务器正在将所有请求指向/public ,所以如何将它们显示在/storage文件夹中?