小编non*_*ame的帖子

Laravel 5.2 - 如何获取新创建的用户的ID并将其传递给控制器

我之前从未使用过Laravel,我正在使用laravels默认用户注册和auth进行3部分注册,用于表单的第1步.每一步都有自己的表.步骤1s表的id列用于链接所有3个表.

目前我正在使用$id = Auth::user()->id在步骤2控制器中获取登录用户ID.相反,如何在创建用户之后将id路由/传递给步骤2控制器存储方法并将视图重定向到步骤2?

在authcontroller中

protected function create(array $data)
{

    return User::create([
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'firstName' => $data['firstName'],
        'middleName' => $data['middleName'],
        'lastName' => $data['lastName'],
    ]);
}
Run Code Online (Sandbox Code Playgroud)

在Illuminate\Foundation\Auth\RegistersUsers;

public function register(Request $request)
{
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    Auth::guard($this->getGuard())->login($this->create($request->all()));

    // pass id to store method in profile and redirect to profileinfo 
    return view('user/profileinfo');
}

}
Run Code Online (Sandbox Code Playgroud)

laravel

5
推荐指数
2
解决办法
5309
查看次数

Laravel 5.2在提交时将表单发布到外部URL

我正在使用第三方支付服务.

<form name="form1" method="post" action="https://exampledomain.com/postpayment.php">
<input type="hidden" name="CRESecureID" value="1"/>
<input type="hidden" name="trans_type" value=" 2"/>
<input type="hidden" name="content_template_url" value="https://example.com/enterpaymentdetails.html"/>
<input type="hidden" name="allowed_types" value=" 3"/>
<input type="hidden" name="total_amt" value="$payment->amount"/>
<input type="hidden" name="collect_total_amt" value="$payment->total"/>
<input type="hidden" name="sess_id" value="e91dd8af53j35k072s0bubjtn7"/>
<input type="hidden" name="sess_name" value="session"/>
<input type="hidden" name="return_url" value="https://example.com/return.html"/>

<p><label> <input type="submit" name="submit" value="submit"/> </label></p>
Run Code Online (Sandbox Code Playgroud)

如何正确地将这些变量发送到外部URL?我应该在控制器中做吗?一个例子会有所帮助.

谢谢

php laravel laravel-5.2

0
推荐指数
1
解决办法
1173
查看次数

C如何阻止文件被覆盖

目前,文件已创建并被覆盖.我试图得到它,如果文件已经存在,它只是退出程序.必须使用open.

if ((dest = open(argv[2], O_WRONLY | O_CREAT, 0644)) == -1) {
    printf("Error File %s exists", argv[2]);
    return 3; 
 }
Run Code Online (Sandbox Code Playgroud)

c unix

-1
推荐指数
1
解决办法
47
查看次数

程序不会停止在EOF上

目前,当我点击ctrl+d它时,一直> ERROR反复打印,直到我暂停程序(ctrl+z).我已经尝试了各种方法来解决这个问题,但它以其他方式打破了程序.

int main()
{
    char *command;      
    char **parameters;  
    int status;     
    size_t buffsize = 0;    

    while(1)
    {
        command = NULL;
        printf("> ");

       getline(&command, &buffsize, stdin);

        command[strlen(command)-1] = '\0';

        parameters = tokenize(command);


        if (!strcmp(command, "exit"))
        {
            exit(1);
        }

        if (fork() != 0) 
        {
            waitpid(-1, &status, 0);
        }
        else
        {
            status = execvp(command, parameters);
            if (status == -1)
            {
                printf("ERROR\n");
                exit(1);
            }
        }
        free(command);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编辑:这是修复.谢谢jil

if(getline(&command, &buffsize, stdin)) == -1) {
     return …
Run Code Online (Sandbox Code Playgroud)

c eof

-1
推荐指数
1
解决办法
66
查看次数

标签 统计

c ×2

laravel ×2

eof ×1

laravel-5.2 ×1

php ×1

unix ×1