我想通过.htaccess 将我站点上/ user目录中的所有文件(无论是否存在)重定向到根目录中名为temp.php的文件.
例如,如果用户输入user/send.php或user /或user/send(可能根本不存在),则全部重定向到temp.php.
我怎样才能做到这一点 ?
我创建了一个用户可以搜索数据库的表单,结果取决于用户填写表单的方式.
例如,假设我有姓名,地址,城市,州和邮政编码字段,并且用户填写姓名和城市字段,结果反映了输入.当表单提交所有记录时都会显示.对此,我写这个:
if(isset($_POST['submit'])) {
$sql = mysql_query("SELECT * FROM table WHERE name LIKE '%" . $_POST['name'] . "%'
OR address LIKE '%" . $_POST['address'] . "%'
OR city LIKE '%" . $_POST['city'] . "%'
OR state LIKE '%" . $_POST['state'] . "%'
OR zip LIKE '%" . $_POST['zip'] . "%'");
}
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<tr>
<td>Name:</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="city" /></td>
</tr>
<tr>
<td>State:</td>
<td><input …Run Code Online (Sandbox Code Playgroud) 我正在使用一种API,用户可以发送文件url将其下载到其名称与用户名相同的特定文件夹中。
首先,我将新磁盘选项添加到名为的文件系统配置中user,该文件具有与经过身份验证的用户名相同的特定目录。像这样:
'disks' => [
'user' => [
'driver' => 'local',
'root' => NULL, //set on the fly after user authentication. (LogAuthenticated.php)
],
'local' => [
'driver' => 'local',
'root' => public_path('files'),
]
]
Run Code Online (Sandbox Code Playgroud)
当用户进行身份验证时,我在Illuminate\Auth\Events\Authenticated事件的侦听器上创建一个与身份验证的用户名相同的目录,并设置filesystems.disks.user.rootconfig,如下所示:
public function handle (Authenticated $event)
{
$username = $event->user->username;
if (!Storage::exists($username)) {
Storage::makeDirectory($username, 0775);
}
Config::set('filesystems.disks.user.root', public_path('files/' . $username));
}
Run Code Online (Sandbox Code Playgroud)
现在,我想从用户提供的外部URL存储文件。假设该文件具有jpg格式,我想photo使用唯一的名称将其存储在用户Directory的目录中。为此我写了这个:
Storage::disk('user')->putFile('photos', fopen($photo, 'r'));
Run Code Online (Sandbox Code Playgroud)
但是当我运行代码时出现此错误:
Call to a member function hashName() on string
Run Code Online (Sandbox Code Playgroud)
我不知道这是什么错误,为什么会发生。如果有人知道,请帮助我。
假设我有这些路线:
$api->group(['prefix' => 'Course'], function ($api) {
$api->group(['prefix' => '/{course}'], function ($api) {
$api->post('/', ['uses' => 'CourseController@course_details']);
$api->post('Register', ['uses' => 'CourseController@course_register']);
$api->post('Lessons', ['uses' => 'CourseController@course_lessons']);
});
});
Run Code Online (Sandbox Code Playgroud)
如您所见,所有/,Register和Lessonsroute 都以course必需参数为前缀。
course参数是Course我想用于路由模型绑定的模型的 ID 。
但另一方面,当我想course在course_details函数中使用参数 时,它返回null. 像这样 :
public function course_details (\App\Course $course)
{
dd($course);
}
Run Code Online (Sandbox Code Playgroud)
但是如果我在下面使用,一切正常:
public function course_details ($course)
{
$course = Course::findOrFail($course);
return $course;
}
Run Code Online (Sandbox Code Playgroud)
似乎无法正确绑定模型。
什么是问题?
更新 :
事实上,我正在使用dingo-api laravel …
我有一个这样的嵌套数组:
$categories = [
['id' => 1, 'name' => 'TV & Home Theather'],
['id' => 2, 'name' => 'Tablets & E-Readers'],
['id' => 3, 'name' => 'Computers', 'children' => [
['id' => 4, 'name' => 'Laptops', 'children' => [
['id' => 5, 'name' => 'PC Laptops'],
['id' => 6, 'name' => 'Macbooks (Air/Pro)']
]],
['id' => 7, 'name' => 'Desktops'],
['id' => 8, 'name' => 'Monitors']
]],
['id' => 9, 'name' => 'Cell Phones']
];
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种在larvel或PHP中将其转换为嵌套组合框的方法,如下所示:
<option value="1">TV & Home …Run Code Online (Sandbox Code Playgroud) 今天通过composer删除spatie/laravel-glide包后,在任何php artisan运行后显示波纹管错误消息:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Spatie\Glide\GlideServiceProvider' not found
Run Code Online (Sandbox Code Playgroud)
我搜索了这个问题并多次调用 bellow statment:
composer dump-auto
Run Code Online (Sandbox Code Playgroud)
但错误继续显示。
这是我的作曲家文件:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"mews/captcha": "^2.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled", …Run Code Online (Sandbox Code Playgroud) 假设我们必须像这样使用 DateTime 格式化日期:
$started_at = '2016-07-05 12:29:16';
$ended_at = '2016-07-06 13:30:10';
Run Code Online (Sandbox Code Playgroud)
现在我想像这样计算它们的小时数、分钟数和秒数:
15 hours and 50 minutes and 15 seconds
Run Code Online (Sandbox Code Playgroud)
我如何在 laravel 和使用Carbon中以最简单的方式做到这一点。
假设我有一个Conversation这样的模型:
class Conversation extends Model
{
public function questions (){
return $this->hasMany('App\Question','conversation_id','conversation_id');
}
public function category ()
{
return $this->belongsTo('App\Category', 'cat', 'cat_id');
}
}
Run Code Online (Sandbox Code Playgroud)
和这样的Question模型:
class Question extends Model
{
public function conversation ()
{
return $this->belongsTo('App\Conversation', 'conversation_id', 'conversation_id');
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,这hasMany两者之间存在关系。
另一方面,Category下面有一个与Conversation模型有关系的类似:
class Category extends Node
{
public function conversations (){
return $this->hasMany('App\Conversation','cat','cat_id');
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想附加一个名为question_countto的属性,Category该属性计算每个类别的所有对话问题。为此,我添加了以下内容:
public function getQuestionsCountAttribute ()
{
return $this->conversations->questions->count();
}
Run Code Online (Sandbox Code Playgroud)
但是当获取一个类别时,我收到了这个错误: …
为了在频道上广播事件,我使用了laravel Echo,redis和socket-io。
这是我的活动:
class ChatNewMessage implements ShouldBroadcast
{
use InteractsWithSockets, SerializesModels;
public $targetUsers;
public $message;
public function __construct ($message)
{
$this->targetUsers = $message->chat->users->pluck('user_id');
$this->message = $message;
}
public function broadcastOn ()
{
$userChannels = [];
foreach ($this->targetUsers as $id) {
$userChannels[] = 'user-channel.' . $id;
}
return $userChannels;
}
public function broadcastAs()
{
return 'NewMessage';
}
}
Run Code Online (Sandbox Code Playgroud)
对于Socket.io服务器,我使用的是laravel-echo-server,下面是配置:
{
"authHost": "http://api.pars-app.dev",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "1924bf1d59b3759d",
"key": "eaf9e3c843493421f4be488fba11f49d"
}
],
"database": …Run Code Online (Sandbox Code Playgroud) php ×8
laravel ×7
laravel-5.3 ×4
laravel-5 ×2
.htaccess ×1
apache ×1
api ×1
arrays ×1
eloquent ×1
laravel-5.4 ×1
laravel-5.5 ×1
mod-rewrite ×1
php-carbon ×1
redis ×1
sockets ×1