对于php–使用LaravelSocialite获取Google刷新令牌感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍谷歌令牌,并为您提供关于Lumen5.5,使用laravelexcel下载
对于php – 使用Laravel Socialite获取Google刷新令牌感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍谷歌令牌,并为您提供关于Lumen5.5,使用laravel excel 下载 、导入excel文件、php artisan migration throwing [PDO异常]找不到驱动程序-使用Laravel、PHP Composer更新“无法分配内存”错误(使用Laravel 4)、php – 使用laravel 4.2中输入的新值更新/替换值的有用信息。
本文目录一览:- php – 使用Laravel Socialite获取Google刷新令牌(谷歌令牌)
- Lumen5.5,使用laravel excel 下载 、导入excel文件
- php artisan migration throwing [PDO异常]找不到驱动程序-使用Laravel
- PHP Composer更新“无法分配内存”错误(使用Laravel 4)
- php – 使用laravel 4.2中输入的新值更新/替换值
php – 使用Laravel Socialite获取Google刷新令牌(谷歌令牌)
$scopes = [ 'https://www.googleapis.com/auth/webmasters','https://www.googleapis.com/auth/webmasters.readonly','https://www.googleapis.com/auth/analytics.readonly','https://www.googleapis.com/auth/userinfo.profile','https://www.googleapis.com/auth/userinfo.email',]; $parameters = ['access_type' => 'offline']; return Socialite::driver('google')->scopes($scopes)->with($parameters)->redirect();
如何获取刷新令牌?
解决方法
return Socialite::driver('google') ->scopes() // For any extra scopes you need,see https://developers.google.com/identity/protocols/googlescopes for a full list; alternatively use constants shipped with Google's PHP Client Library ->with(["access_type" => "offline","prompt" => "consent select_account"]) ->redirect();
Lumen5.5,使用laravel excel 下载 、导入excel文件
首先是安装laravel excel,使用composer安装
composer
require
maatwebsite/excel ~2.1.0
2、配置
在bootstrap/app.php中,加入如下配置:
//使用 laravel-excel
$app->register(Maatwebsite\Excel\ExcelServiceProvider::class);
3、导入excel,定义好路由,上传excel文件到后台,使用如下方法,可直接解析出excel的数据
$file = $request->file(''myfile'');
//获取数组类型的数据
$results = Excel::load($file)->get()->toArray();
到这里还没完,你会发现导入的文件,信息获取不完整,中文得不到,需要在
maatwebsite/excel/src/config/excel.php之下修改:
''to_ascii'' =>true 改成 ''to_ascii'' => false,
这个很坑。这样导入就完成了。
-------------------------------------------------------------------------------------------------------------------------
下载Excel
1、可以直接在路由配置
Route::get(''download'',function(){
return response()->download(realpath(base_path(''public'')).''/student.xlsx'', ''student.xlsx'');
});
然后在浏览器访问这条路径,就可以的下载了,也可封装成方法:
public static function downLoad($fileName,$goalFileName=''StudentExample''){
$path =realpath(base_path(''public'')).''/''.$goalFileName.''.xlsx'';
return response()->download($path,$fileName.''.xlsx'');
}
然后可以使用js,打开窗口,下载文件
let url = APP.$Api.getExampleExcel();
window.open(url);
这里是在vue中的写法,
APP
.
$Api
.
getExampleExcel
()获取后台地址
php artisan migration throwing [PDO异常]找不到驱动程序-使用Laravel
我在安装laravel时遇到了不好的经验。但是,我能够这样做,并进入了新的高度。我使用生成器并创建了迁移。但是当我键入最后一条命令时
php artisan migrate
它引发PDOException-找不到驱动程序。
''mysql'' => array( ''driver'' => ''mysql'', ''host'' => ''localhost'', ''unix_socket'' => ''/Applications/MAMP/tmp/mysql/mysql.sock'', ''database'' => ''database'', ''username'' => ''root'', ''password'' => '''', ''charset'' => ''utf8'', ''collation'' => ''utf8_unicode_ci'', ''prefix'' => '''', ),
那是我在config / database.php中的配置。
我尝试在stackoverflow和laravel论坛上进行搜索,人们认为这是PDO问题,而不是artisan或php的问题-我遵循这些建议,例如添加
extension=pgsql.soextension=pdo_pgsql.so
在php.ini中
没有积极的结果。总是说[PDOException]could not find driver.
有人可以帮忙解决这个问题吗?
我正在使用的环境:Mac,laravel 4,带有AMP 5.4.4的MAMP PRO
答案1
小编典典您可以使用
sudo apt-get install php7-mysql
要么
sudo apt-get install php5-mysql
要么
sudo apt-get install php-mysql
这对我有用。
PHP Composer更新“无法分配内存”错误(使用Laravel 4)
我只是无法解决这个问题。
我正在使用Linode 1G RAM基本计划。试图通过Composer安装软件包,但并没有让我这么做。我的内存限制在PHP.ini上设置为“ -1”
我还能做些什么来安装此软件吗?
Loading composer repositories with package informationUpdating 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:975Stack 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): proc_open(''stty -a | grep ...'', Array, NULL, NULL, NULL, Array)#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(853): Symfony\Component\Console\Application->getSttyColumns()#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(818): Symfony\Component\Console\Application->getTerminalDimensions()#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(752): Symfony\Component\Console\Application->getTerminalWidth()#5 phar:///usr/local/bin/com in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 975Fatal 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:975Stack 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): proc_open(''stty -a | grep ...'', Array, NULL, NULL, NULL, Array)#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(853): Symfony\Component\Console\Application->getSttyColumns()#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(818): Symfony\Component\Console\Application->getTerminalDimensions()#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(752): Symfony\Component\Console\Application->getTerminalWidth()#5 phar:///usr/local/bin/com in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 975
答案1
小编典典有点老了,但是以防万一有新人正在寻找解决方案,更新您的PHP版本可以解决此问题。
另外,您应该提交composer.lock文件,并在资源占用较少的生产环境中进行composer安装。
此处有更多详细信息:https
:
//github.com/composer/composer/issues/1898#issuecomment-23453850
php – 使用laravel 4.2中输入的新值更新/替换值
我们知道laravel有一个update()方法,通过“put”http方法更新记录.除非我尝试在我的用户模型中针对静态$rules方法验证新输入值,否则一切都很酷.
请看看我的模特
protected $guarded = ['id', 'admin'];
public static $rules = [
'name' => 'required|min:4',
'username' => 'required|min:3|alpha_num|unique:users',
'email' => 'required|email|unique:users',
'password' => 'required|alpha_num|between:5,12|confirmed',
'password_confirmation' => 'required|alpha_num|between:5,12',
'phone' => 'required|min:5|alpha_num',
'city' => 'required|min:2|alpha',
'town' => 'required|min:2|alpha_num',
'address' => 'required|min:5|alpha_num',
'blood' => 'required|min:2',
'img' => 'image|mimes:jpeg,jpg,bmp,png,gif',
'active' => 'integer',
'admin' => 'integer'
];
您看到我已将电子邮件设置为用户表的唯一身份.因此,当我尝试更新记录时,这些记录与登录用户的个人资料信息有关,如果我更新所有记录以及它的工作电子邮件地址.但是,如果我按原样保留电子邮件字段,则会抛出验证错误,指出电子邮件地址已被删除.
但我希望laravel只验证更新的字段,以便用户可以更新他们想要的内容或像以前一样留下一两个.
有没有办法实现这一目标?
现在请查看负责更新新输入数据的控制器方法
//update the changes Now
public function update($id) {
$user = User::find($id);
$validator = Validator::make(Input::all(), User::$rules);
$input = array_except(Input::all(), ['_method', 'password_confirmation']);
if( $validator->passes() ) {
$user->save($input);
return Redirect::to('donors/'.$user->username.'/profile')
->withMessage('information Updated');
}
return Redirect::to('donors/'.$user->username.'/profile/edit')
->withMessage('Something went wrong! Please fix the errors.')
->withErrors($validator)
->withinput();
}
为了更清楚地理解场景,我还在视图和路径文件片段中添加表单.
路线
Route::put('donors/{id}', ['uses'=>'DonorsController@update']);
观点形式
{{ Form::open(['url'=>'donors/'.$donor->id, 'method'=>'put', 'role'=>'form']) }}
<tablehttps://www.jb51.cc/tag/nor/" target="_blank">nors-table">
<colgroup>
<col>
<col>
</colgroup>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span>Name</span>
</td>
<td>
{{ Form::text('name', $donor->name) }}
<span>{{ $errors->first('name') }}</span>
</td>
</tr>
<tr>
<tr>
<td>
<span>Email</span>
</td>
<td>
{{ Form::email('email', $donor->email) }}
<span>{{ $errors->first('email') }}</span>
</td>
</tr>
<tr>
<td>
<span>New Password</span>
</td>
<td>
{{ Form::password('password', null) }}
<span>{{ $errors->first('password') }}</span>
</td>
</tr>
<tr>
<td>
<span>Confirm New Password</span>
</td>
<td>
{{ Form::password('password_confirmation', null) }}
<span>{{ $errors->first('password_confirmation') }}</span>
</td>
</tr>
<tr>
<td>
<span>Blood Group</span>
</td>
<td>
{{ Form::text('blood', $donor->blood) }}
<span>{{ $errors->first('blood') }}</span>
</td>
</tr>
<tr>
<tr>
<td>
<span>Address</span>
</td>
<td>
{{ Form::text('address', $donor->address) }}
<span>{{ $errors->first('address') }}</span>
</td>
</tr>
<tr>
<td>
<span>City</span>
</td>
<td>
{{ Form::text('city', $donor->city) }}
<span>{{ $errors->first('city') }}</span>
</td>
</tr>
<tr>
<td>
<span>Town</span>
</td>
<td>
{{ Form::text('town', $donor->town) }}
<span>{{ $errors->first('town') }}</span>
</td>
</tr>
<tr>
<td>
<span>Phone</span>
</td>
<td>
{{ Form::text('phone', $donor->phone) }}
<span>{{ $errors->first('phone') }}</span>
</td>
</tr>
<tr>
</tbody>
</table>
<p>
{{ Form::submit('Update', ['class'=>'btn btn-success pull-left']) }}
{{ link_to('donors/'.$donor->username.'/profile', 'Cancel', ['class'=>'pull-right btn btn-danger']) }}
</p>
{{ Form::close() }}
我有什么不想错的吗?
如果我应该显示我的代码的任何其他代码段,请告诉我.
解决方法:
要进行更新,您需要稍微更改电子邮件规则.如果作为唯一规则的一部分,您传递字段以进行检查,然后输入值,则不会抱怨该值已被采用.
在您的情况下,在进行验证之前,通过放置以下内容来更新控制器:
User::$rules['email'] = 'required|email|unique:users,email,' . Input::get['email'];
您的验证现在应该通过,因为您告诉laravel该电子邮件应该是唯一的,但您将接受当前的电子邮件地址.
今天关于php – 使用Laravel Socialite获取Google刷新令牌和谷歌令牌的分享就到这里,希望大家有所收获,若想了解更多关于Lumen5.5,使用laravel excel 下载 、导入excel文件、php artisan migration throwing [PDO异常]找不到驱动程序-使用Laravel、PHP Composer更新“无法分配内存”错误(使用Laravel 4)、php – 使用laravel 4.2中输入的新值更新/替换值等相关知识,可以在本站进行查询。
本文标签: