I'm currently trying to use an angular feature, but I cant use ng-click inside an a react app.
I am trying to convert the following function to a react function, I'm aware of axios, not sure how to approach blade variables in react.
I need the angular snippet to do be converted into a react function.
Angular(main.js)
$scope.myfollow = function(user) {
$http.post('/user/follow/'+ user.id).then(function(result) {
console.log("user id is:"+ user.id);
});
};
React file
render(){
return(
<div className="followdoe">
<button onClick={ this.btnClick.bind(this) } className={this.state.className}>
<p>{ this.state.btnText }</p>
</button>
</div>
)
}
Route.php
Route::post('user/follow/{id}', 'UserController@my_follow');
Profile.blade.php
<div style="margin:30px 0px;">
<button class="follow-button" ng-click="myfollow({{$user}});">+ Follow</button>
</div>
UserController.php
public function my_follow(Request $request, $id)
{
$user = auth()->user();
if($user->id != $id && $otherUser = User::find($id)){
$user->toggleFollow($otherUser);
}
}
public function getProfile($user)
{
$user = User::with(['posts.likes' => function($query) {
$query->whereNull('deleted_at');
}, 'follow','follow.follower'])
->where('name','=', $user)->first();
if(!$user){
return redirect('404');
}
return view ('profile')->with('user', $user);
}
userdata in your React component?myfollowfunction to React. I'm not sure how your data looks beyond that, I'm afraid.