Skip to main content

Add Category with Floating Button

Premium
5:12

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

BM
Ben McKay ✓ Link copied!

I ran into another issue here where I was getting an error, but nothing was giving me feedback on the Flutter app side. I ended up going to my Laravel app and looked at the logs. You have to change your CategoryController to just store the Category with a logged in user. Here is what I did temporarily.

$category = Category::create($request->validated());
//$category = auth()->user()->categories()->create($request->validated());

Once we log in our user in the tutorial, I can go back to the other way I believe.

M
marko_mo ✓ Link copied!

What I've done is creating token by authenticating through Postman and then adding it to global variable so it can be used before we get to the Register/Login through the app.

class ApiService {
 
ApiService();
 
String token = "your------toke";
final String baseURL = "http://your-base-url:8000/api/";
 
Future<List<Category>> fetchCategories() async {
http.Response response = await http.get(
Uri.parse(baseURL + "categories"),
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.acceptHeader: 'application/json',
HttpHeaders.authorizationHeader: 'Bearer $token',
}
);
print(response.body);
List categories = jsonDecode(response.body);
return categories.map((category) => new Category.fromJson(category)).toList();
}
}
 
class Category {
int id;
String name;
 
Category({
required this.id,
required this.name,
});
factory Category.fromJson(Map<String, dynamic> json) {
return Category(
id: json['id'],
name: json['name'],
);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.